当前位置: 技术问答>java相关
老子毛了,谁给我解决这问题,我把分全给他
来源: 互联网 发布时间:2015-01-17
本文导语: 问题:1:在版面上绘制一条直线,2:装设一个Timer对象,每隔0.5秒变换一个颜色,按顺序是红黄绿色我已经完成1部分,但是不知道第二部分怎么办,请指教!! import java.awt.*; import javax.swing.*; import java.awt.event.*; //M...
问题:1:在版面上绘制一条直线,2:装设一个Timer对象,每隔0.5秒变换一个颜色,按顺序是红黄绿色我已经完成1部分,但是不知道第二部分怎么办,请指教!!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
//MyWindowListener;//
public class eleven1 extends JFrame
{
public eleven1()
{
super("ready");
setSize(500,80);
show();
}
public void paint(Graphics g)
{
Font font=new Font("Serif",Font.BOLD,20);
g.setFont(font);
g.drawString("按顺序变换水平线为红绿蓝色",60,60);
g.drawLine(60,70,400,70);
}
public static void main(String args[])
{
eleven1 app=new eleven1();
app.addWindowListener(new MyWindowListener());
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
//MyWindowListener;//
public class eleven1 extends JFrame
{
public eleven1()
{
super("ready");
setSize(500,80);
show();
}
public void paint(Graphics g)
{
Font font=new Font("Serif",Font.BOLD,20);
g.setFont(font);
g.drawString("按顺序变换水平线为红绿蓝色",60,60);
g.drawLine(60,70,400,70);
}
public static void main(String args[])
{
eleven1 app=new eleven1();
app.addWindowListener(new MyWindowListener());
}
}
|
//完整的代码,直接编译后可运行
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
//add by iame
import java.awt.event.*;
class MyWindowListener extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(1);
}
}
public class eleven1 extends JFrame implements ActionListener
{
//add by iame
Timer timer=new Timer(500,this);
Color[] colors={Color.red,Color.green,Color.blue};
int index=0;
public eleven1()
{
super("ready");
setSize(500,80);
show();
timer.start();
}
public void actionPerformed(ActionEvent e)
{
index++;
repaint();
}
public void paint(Graphics g)
{
Font font=new Font("Serif",Font.BOLD,20);
//add by iame
g.setColor(colors[index%3]);
g.setFont(font);
g.drawString("按顺序变换水平线为红绿蓝色",60,60);
g.drawLine(60,70,400,70);
}
public static void main(String args[])
{
eleven1 app=new eleven1();
app.addWindowListener(new MyWindowListener());
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
//add by iame
import java.awt.event.*;
class MyWindowListener extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(1);
}
}
public class eleven1 extends JFrame implements ActionListener
{
//add by iame
Timer timer=new Timer(500,this);
Color[] colors={Color.red,Color.green,Color.blue};
int index=0;
public eleven1()
{
super("ready");
setSize(500,80);
show();
timer.start();
}
public void actionPerformed(ActionEvent e)
{
index++;
repaint();
}
public void paint(Graphics g)
{
Font font=new Font("Serif",Font.BOLD,20);
//add by iame
g.setColor(colors[index%3]);
g.setFont(font);
g.drawString("按顺序变换水平线为红绿蓝色",60,60);
g.drawLine(60,70,400,70);
}
public static void main(String args[])
{
eleven1 app=new eleven1();
app.addWindowListener(new MyWindowListener());
}
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。