JAVA界面程序

来源:百度知道 编辑:UC知道 时间:2024/06/18 07:14:21
public class Main extends JFrame {

private static JFrame f ;
public static void main(String[] args)
{
f = new JFrame("sdfe");
new Main();

}
public Main()
{
f.setSize(200,200);
f.setVisible(true);
f.getContentPane().add(new NewClass());
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class NewClass extends Component implements Runnable
{
String s = "hello";

public NewClass()
{
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
protected void processMouseEvent(MouseEvent e)
{

if(e.getID()==MouseEvent.MOUSE_PRESSED)
{
new Thread(this).start();
}
}

public void paint(Graphics g)
{
g.setColor(Color.BLUE);
g.dra

paint方法是程序开始就运行一次,所以不要在里面直接画出来,应该定义一个draw方法,按鼠标后,先调用draw方法后再重画(repaint);具体程序我就不写了,如果还是不明白就发邮件给我ourlove520@hotmail.com

首先 哥们,你够抠的...看程序

其次呢..我没看懂...不好意思了