?? roundbutton.java.bak
字號(hào):
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.net.*;
public class RoundButton extends JButton
{
public RoundButton(String label)
{
super(label);
Dimension size=getPreferredSize();
setPreferredSize(size);
setContentAreaFilled(false);
}
protected void paintComponent(Graphics g)
{
if(getModel().isArmed())
{
g.setColor(Color.lightGray);
}
else
{
g.setColor(getBackground());
}
g.fillOval(0,0,getSize().width-1,getSize().height-1);
super.paintComponent(g);
}
protected void paintBorder(Graphics g)
{
g.setColor(getForeground());
g.drawOval(0,0,getSize().width-1,getSize().height-1);
}
Shape shape;
public boolean contains(int x,int y)
{
if(shape==null||!shape.getBounds().equals(getBounds()))
{
shape=new Ellipse2D.Float(0,0,getWidth(),getHeight());
}
return shape.contains(x,y);
}
public static void main(String[] args)
{
JButton button=new RoundButton("圓形按鈕");
JButton b2;
ImageIcon ic;
button.setBackground(Color.green);
ic=new ImageIcon("Red.GIF");
b2=new JButton(ic);
JFrame frame=new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setBackground(Color.yellow);
frame.getContentPane().add(button);
frame.getContentPane().setLayout(new FlowLayout());
frame.setSize(300,200);
frame.setVisible(true);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -