public class InvisibleButton extends JButton implements ActionListener { String text; Font inactiveFont; Font activeFont; Border activeBorder; Border inactiveBorder;
public InvisibleButton(String Text, Color Background) { super.setText(Text); super.setBorder(new EmptyBorder(0, 0, 0, 0));
setOpaque(false);
if (Background.getRGB() == -1118482) { Background = Color.white;
} this.setBackground(Background); cont(); }
public InvisibleButton(String Text, String ToolTipText, Color Background) { this.setText(Text); this.setToolTipText(ToolTipText); this.setBorder(new EmptyBorder(0, 0, 0, 0)); setOpaque(false);
if (Background.getRGB() == -1118482) { Background = Color.white;
} this.setBackground(Background); cont(); }
public void cont() { this.addActionListener(this);
System.out.println();
inactiveFont = new Font(getFont().getFontName(), getFont().getStyle(), getFont().getSize() ); activeFont = new Font(getFont().getFontName(), Font.BOLD | Font.ITALIC, getFont().getSize()); activeBorder = new EmptyBorder(0, 0, 2, 0);
public void actionPerformed(ActionEvent e) { System.exit(0); }
public static void main(String a[]) { Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER)); JFrame frame = new JFrame(); p.setBackground(new Color(232, 222, 122)); System.out.println(p.getBackground().getRGB()); InvisibleButton b = new InvisibleButton("Do me a favour and press me", p.getBackground());
This is my attempt to create a custom Button When i create objects of this class(InvisibleButton ) it does evrything it's supposed to except handle events.