这个程序可以这样实现吗?
有一个java程序,就是一个窗口上有2个按钮(一个隐藏,一个显示),要求按一个按钮,另一个就出现,而它自己隐藏。我想这样实现:一个frame里有两个Panel,每个里面有一个button,设置初始状态为一个可见一个不可见,setVisible(true),和setVisible(false),程序在下面,编译没问题,可他说没主程序,可我明明有入口,这是错了吗?为什么?
import java.awt.*;
import java.awt.event.*;
public class Buttonhide implements MouseListener,WindowListener
{
/**
* @param args
*/
private Frame f;
private Panel p1;
private Panel p2;
private Button b1;
private Button b2;
boolean i=true;
boolean j=false;
boolean temp;
public static void main(String[] args)
{
Buttonhide one = new Buttonhide();
one.go();
}
public void go()
{
f=new Frame("i'm xuwei");
b1=new Button("button1");
b2=new Button("button2");
b1.addMouseListener(this);
b2.addMouseListener(this);
f.addWindowListener(this);
f.setLayout(new BorderLayout());
f.setSize(200,200);
f.setVisible(true);
f.add(p1,"north");
f.add(p2,"south");
p1.add(b1);
p2.add(b2);
p1.setVisible(i);
p2.setVisible(j);
}
public void mouseClicked(MouseEvent e)
{
temp=i;
i=j;
j=temp;
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
}