首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

懂的帮忙看看用eclipse写得java程序,多谢啦

2012-09-17 
懂的帮忙看看用eclipse写得java程序,谢谢啦!import java.awt.*import java.awt.event.*public class Bio

懂的帮忙看看用eclipse写得java程序,谢谢啦!
import java.awt.*;
import java.awt.event.*;

public class Bios {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
  Frame f = new Frame("Activity");
  Button b1 = new Button("button1");
  Button b2 = new Button("button2");
  Panel p1 = new Panel();
  Panel p2 = new Panel();
  f.setLayout(new FlowLayout());
  MyWindowMonitor wm = new MyWindowMonitor();
  f.addWindowListener(wm);
  b1.addActionListener(new Monitor1());
  b2.addActionListener(new Monitor2());
  f.add(p1);
  f.add(p2);
  f.add(b1);
  f.add(b2);
  p1.setVisible(true);
  p2.setVisible(true);
  f.setLocation(400,300);
  f.setSize(400,300);
  f.setVisible(true);
}



class Monitor1 implements ActionListener{
public void actionPerformed(ActionEvent e){
p1.setVisible(true);
p2.setVisible(false);
}
}

class Monitor2 implements ActionListener{
public void actionPerformed(ActionEvent e){
p2.setVisible(true);
p1.setVisible(false);
}
}

class MyWindowMonitor extends WindowAdapter {
public void sondowClosing(WindowEvent e){
f.setVisible(false);
System.exit(0);

}
}
   
}


红色的字体是eclipse 显示出错的地方,懂的看看这是什么错误

[解决办法]

Java code
import java.awt.*;import java.awt.event.*;public class Bios {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stub  Frame f = new Frame("Activity");  Button b1 = new Button("button1");  Button b2 = new Button("button2");  Panel p1 = new Panel();  Panel p2 = new Panel();  f.setLayout(new FlowLayout());  MyWindowMonitor wm = new MyWindowMonitor();  f.addWindowListener(wm);  b1.addActionListener(new ActionListener{  public void actionPerformed(ActionEvent e){  p1.setVisible(true);  p2.setVisible(false);  }});  b2.addActionListener(new ActionListener{  public void actionPerformed(ActionEvent e){  p2.setVisible(true);  p1.setVisible(false);  }});  f.add(p1);  f.add(p2);  f.add(b1);  f.add(b2);  p1.setVisible(true);  p2.setVisible(true);  f.setLocation(400,300);  f.setSize(400,300);  f.setVisible(true);}
[解决办法]
Monitor1 Monitor2不要了 窗口监听器改一下:
Java code
class MyWindowMonitor extends WindowAdapter {public void sondowClosing(WindowEvent e){[color=#FF0000](Frame)e.getSource().setVisible(false);[/color]System.exit(0);}} 

热点排行