paintjbutton.java
来自「java相关的j2me,j2se的一些相关资料」· Java 代码 · 共 39 行
JAVA
39 行
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class PaintJButton extends JButton {
public PaintJButton(String name) {
super(name);
this.setContentAreaFilled(false);
}
protected void paintComponent(Graphics g){
g.setColor(Color.LIGHT_GRAY);
g.fillOval(0,0,200,35);
}
public static void main(String args[]){
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (IllegalAccessException ex) {}
catch (ClassNotFoundException ex) {}
catch (UnsupportedLookAndFeelException ex) {}
catch (InstantiationException ex) {}
JFrame frame = new JFrame();
frame.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(100,100,500,500);
frame.setVisible(true);
PaintJButton button = new PaintJButton("dddddddd");
button.setVisible(true);
button.setBounds(200,200,350,350);
frame.add(button);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?