import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame implements ActionListener
{
JButton test = new JButton("test");
JButton ve = new JButton("ve");
Container c = this.getContentPane();
boolean u=true;
public Main()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(new FlowLayout());
test.addActionListener(this);
ve.addActionListener(this);
c.add(test);
c.add(ve);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==test) //为什么不能在屏幕上删除ve
{
if(u) c.remove(ve);
else c.add(ve);
u=!u;
pack();
show();
}
}
public static void main(String args[])
{
Main mainFrame = new Main();
mainFrame.setSize(300,300);
mainFrame.setTitle("简易计算器");
mainFrame.setVisible(true);
mainFrame.setResizable(false);
}
}
//终于搞定啦,居然会犯这种错误