本题的功能是定义图形按钮。窗口中有两个图形按钮,当鼠标移上去时,图形按钮的图形将改变,用鼠标单击按钮时图形按钮的图形又发生改变,当鼠标左键松开或者移开鼠标后,图形按钮的图形又恢复原样。import javax.swing.*;import java.awt.*;public class java3 extend Jbutton{public java3(Icon icon,Icon pressed,Icon rollover){this(icon);setFocusPainted(false);setRolloverEnabled(true);setRolloverlcon(rollover);setPressedIcon(pressed);setBorderPainted(false);setContentAreaFilled(false);}public static void main(String[]args){java3 b1=new java3(new ImageIcon("java3-redcube.gif"),new ImageIcon("java3-redpaw.gif"),new ImageIcon("java3-reddiamond.gif"));java3 b2一new java3(new ImageIcon("java3-bluecube.gif")。new ImageIcon("java3-bluepaw.gif"),new ImageIcon("java3-bluediamond.gif"));JFrame. f=new JFrame();f.setTitle("java3");f.setDefauhCloseOperation(JFrame.EXIT_ON_CLOSE);c=f.getContentpane();c.setLayout(new FlowLayout());c.add(b1);c.add(b2);f.pack();f.setVisible(true);
本题的功能是定义图形按钮。窗口中有两个图形按钮,当鼠标移上去时,图形按钮的图形将改变,用鼠标单击按钮时图形按钮的图形又发生改变,当鼠标左键松开或者移开鼠标后,图形按钮的图形又恢复原样。
import javax.swing.*;
import java.awt.*;
public class java3 extend Jbutton{
public java3(Icon icon,Icon pressed,Icon rollover){
this(icon);
setFocusPainted(false);
setRolloverEnabled(true);
setRolloverlcon(rollover);
setPressedIcon(pressed);
setBorderPainted(false);
setContentAreaFilled(false);
}
public static void main(String[]args){
java3 b1=new java3(
new ImageIcon("java3-redcube.gif"),
new ImageIcon("java3-redpaw.gif"),
new ImageIcon("java3-reddiamond.gif"));
java3 b2一new java3(
new ImageIcon("java3-bluecube.gif")。
new ImageIcon("java3-bluepaw.gif"),
new ImageIcon("java3-bluediamond.gif"));
JFrame. f=new JFrame();
f.setTitle("java3");
f.setDefauhCloseOperation(JFrame.EXIT_ON_
CLOSE);
c=f.getContentpane();
c.setLayout(new FlowLayout());
c.add(b1);
c.add(b2);
f.pack();
f.setVisible(true);