题目目的是:放一个BUTTON 我每点击一下,BUTTON的尺寸会相应的增大 点到一定的大小 再点击就会缩小 如果已缩小到原有的尺寸 再点又回增大 就这样反复 算是一个GUI的练习吧... 可是我现在连最基本的把他点大都出现了问题 我的代码如下: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.JComponent;
public class Fiona extends JFrame implements ActionListener,MouseListener { private JButton b=new JButton("Succeeds by a quiet attitude"); private Panel p=new Panel(); public Fiona() { this.setSize(350,250); this.setBackground(Color.lightGray); this.setTitle("Natsumi Abe"); this.getContentPane().add(p,BorderLayout.CENTER); //p.scrollRectToVisible(); p.add(b); Border border=BorderFactory.createBevelBorder(BevelBorder.LOWERED, new Color(45,92,162), new Color(43,66,97), new Color(45,92,162), new Color(84,123,200)); //使窗体产生立体感
b.setForeground(Color.cyan); b.addActionListener(this); this.setVisible(true); } public void actionPerformed(ActionEvent e) { int x=0,y=0,w=0,h=0; w=b.getWidth(); h=b.getHeight(); x=b.getX(); y=b.getY(); b.setBorder(BorderFactory.createEmptyBorder(x,y,w+10,h+10)); } public void mouseClicked(MouseEvent e) { /*if(e.getSource()==b) { final int i=140,j=15; final int x=50,y=10; b.setSize(i+x,j+y); }*/ } public void mousePressed(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String args[]) { new Fiona(); } } 望朋友指导.如果无法做出全部.能否先指导我如何点它,它自动增大尺寸...