日期:2014-05-20 浏览次数:20859 次
public class AAA extends JFrame{
public AAA(){
JButton j1=new JButton("12");
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300,300);
add(j1);
j1.setLocation(this.getSize().width-150,100);
j1.setSize(100,20);
// j1.addActionListener(new ActionListener() {
//
// @Override
// public void actionPerformed(ActionEvent e) {
// AAA.this.repaint();
// }
// });
setVisible(true);
}
public static void main(String[] args) {
new AAA();
}
}
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
public class AAA extends JFrame {
public AAA(){
JButton j1=new JButton("12");
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300,300);
add(j1);
j1.setLocation(this.getSize().width-150,100);
j1.setSize(100,20);
j1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
AAA.this.repaint();
}
});
setVisible(true);
}
@Override
public void paint(Graphics g) {
super.paint(g); //To change body of overridden methods use File | Settings | File Templates.
System.out.println("repaint");
}
public static void main(String[] args) {
new AAA();
}
}