完整的代码是这样的
import javax.swing.*;
import java.awt.Graphics;
import java.awt.*;public class Main extends JFrame {/**
* @param args the command line arguments
*/
public static void main(String[] args) {
JFrame frame = new Main();ovalButton button1 = new ovalButton();
ovalButton button2 = new ovalButton();button1.setText("OK");
button2.setText("CANCEL");frame.add(button1);
frame.add(button2);
frame.setTitle("hello");
frame.setLocationRelativeTo(null);
frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200,200);
frame.setVisible(true);
}
}
class ovalButton extends JButton {protected void painComponent(Graphics g){
super.paintComponent(g);g.drawOval(this.getX(), this.getY(), this.getWidth() , this.getHeight()); 
}
}可是椭圆画不出来啊 - - ,不知道为什么......请指教,哈哈thanks