是一个applet程序,代码如下(教我的老师是个教授,当时问的匆忙 他也没看出啥名堂) 求教各位达人
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication2;/**
*
* @author Administrator
*/
import java.awt.*;
import javax.swing.*;
class Sanjiao extends JPanel implements Runnable{
static int[][] x = {{200,400,300},{250,450,350},{300,500,400},{350,550,450},
{300,500,400},{250,450,350},{200,400,300}};//三角形横坐标
static int[] y = {100,100,200};//三角形纵坐标
int[] a =new int[3];
int j=0;
public void paintComponent(Graphics g){
super.paintComponent(g);
for(int i=0;i<3;i++)
{a[i]=x[j][i];}
g.drawPolygon(a, y, 3);
j = (j+1)%7;
}
public void run()
{
while(true)
{
repaint();
try{
Thread.sleep(200);
}catch(InterruptedException e){}
}
}
}
public class SanjiaoDemo extends JApplet
{
Sanjiao sj = new Sanjiao();
public void init ()
{
setSize(1000,500);//设置窗口大小
add(sj,BorderLayout.CENTER);
}
public void start()
{
while(true){
Thread t = new Thread(sj);
t.start();
}
}
}
javaapplet
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication2;/**
*
* @author Administrator
*/
import java.awt.*;
import javax.swing.*;
class Sanjiao extends JPanel implements Runnable{
static int[][] x = {{200,400,300},{250,450,350},{300,500,400},{350,550,450},
{300,500,400},{250,450,350},{200,400,300}};//三角形横坐标
static int[] y = {100,100,200};//三角形纵坐标
int[] a =new int[3];
int j=0;
public void paintComponent(Graphics g){
super.paintComponent(g);
for(int i=0;i<3;i++)
{a[i]=x[j][i];}
g.drawPolygon(a, y, 3);
j = (j+1)%7;
}
public void run()
{
while(true)
{
repaint();
try{
Thread.sleep(200);
}catch(InterruptedException e){}
}
}
}
public class SanjiaoDemo extends JApplet
{
Sanjiao sj = new Sanjiao();
public void init ()
{
setSize(1000,500);//设置窗口大小
add(sj,BorderLayout.CENTER);
}
public void start()
{
while(true){
Thread t = new Thread(sj);
t.start();
}
}
}
javaapplet
解决方案 »
- Java中 是不是只有按值传递 和按引用传递?按址传递的说法错的吧?求高手肯定一下。
- 程序如何调用另一程序?java
- JAVA中如何从文本文件中搜索数据!!!急呀!!!
- 提一个窗口失效的问题??谢了
- 紧急求助:关于EMAIL地址的STRUCTS的校验问题
- 如何在JTable的单元格里添加JButton?
- 请帮看看错在那里
- 【求解】从数据库复制资料到数组中失败
- Java i/o 中的相对地址的问题,怎么写???
- to Apocalypse(逍遥思辨)等高手,请继续帮帮我吧!JTable刷新后鼠标事件怎没了?
- 在java中多线程中,如何让一个上一个线程执行完成后,才开始下一个线程执行
- 什么时候用抽象类,什么时候用接口?
Sanjiao sj = new Sanjiao(); public void init() {
setSize(1000, 500);// 设置窗口大小
//
add(sj, BorderLayout.CENTER); } public void start() {
//while (true) {
Thread t = new Thread(sj);
t.start();
//}
}
}