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);}}