日期:2014-05-20 浏览次数:20942 次
public class MyFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel panel;
private JButton button;
public MyFrame()
{
setSize(new Dimension(400,300));
setLayout(new BorderLayout());
panel=new JPanel();
JScrollPane js=new JScrollPane(panel);
panel.setBackground(Color.RED);
getContentPane().add(js,BorderLayout.NORTH);
button=new JButton("点击变大");
button.setSize(100, 50);
add(button,BorderLayout.SOUTH);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
int x=MyFrame.this.getPanel().getWidth();
int y=MyFrame.this.getPanel().getHeight()+20;
MyFrame.this.getPanel().setSize(x, y);
MyFrame.this.repaint();
}
});
getContentPane().add(button,BorderLayout.SOUTH);
setVisible(true);
}
public JPanel getPanel()
{
return this.panel;
}
public static void main(String[] args)
{
new MyFrame();
}
}