Created
November 30, 2012 08:15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ uname -a | |
Linux sun-Inspiron-One-2320 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux | |
$ java -version | |
java version "1.7.0_09" | |
OpenJDK Runtime Environment (IcedTea7 2.3.3) (7u9-2.3.3-0ubuntu1~12.10.1) | |
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode) | |
import java.awt.Color; | |
import java.awt.Cursor; | |
import java.awt.Dimension; | |
import java.awt.EventQueue; | |
import java.awt.FlowLayout; | |
import java.awt.Font; | |
import java.awt.Graphics; | |
import java.awt.Graphics2D; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.awt.event.MouseAdapter; | |
import java.awt.event.MouseEvent; | |
import java.awt.font.FontRenderContext; | |
import java.awt.font.TextLayout; | |
import java.awt.image.BufferedImage; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import javax.imageio.ImageIO; | |
import javax.swing.ImageIcon; | |
import javax.swing.JButton; | |
import javax.swing.JFrame; | |
import javax.swing.JLabel; | |
public class MouseMethods implements ActionListener { | |
private JLabel label = new JLabel("This is a JLabel"); | |
private JButton button = new JButton("This is a JButton"); | |
private JButton top = new MyIconJButton("belgium_flag_button", "Deutsch", 133, 55); | |
public MouseMethods() { | |
JFrame frame = new JFrame("MouseMethods"); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
frame.setLayout(new FlowLayout()); | |
button.addActionListener(this); | |
top.addActionListener(this); | |
//frame.getContentPane().addMouseListener(this); | |
frame.add(label); | |
frame.add(button); | |
frame.add(top); | |
frame.pack(); | |
frame.setVisible(true); | |
} | |
public static void main(String args[]) { | |
EventQueue.invokeLater(new Runnable() { | |
@Override | |
public void run() { | |
new MouseMethods(); | |
} | |
}); | |
} | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
if (e.getSource().equals(button)) { | |
System.out.println("The JButton1 was clicked..."); | |
} else if (e.getSource().equals(top)) { | |
System.out.println("The JButton2 was clicked..."); | |
} else { | |
System.out.println("Something else was clicked..."); | |
} | |
} | |
public class MyIconJButton extends JButton { | |
private BufferedImage imageGui; | |
private int w = 0; | |
private int h = 0; | |
public MyIconJButton(String name, String toolTip, int ww, int hh) { | |
w = ww; | |
h = hh; | |
try { | |
imageGui = ImageIO.read((InputStream) | |
MyIconJButton.class.getResourceAsStream("/image/menu/" + name + ".png")); | |
ImageIcon iconDefault = new ImageIcon(imageGui); | |
//setIgnoreRepaint(true); | |
setFocusable(false); | |
setBorder(null); | |
setContentAreaFilled(false); | |
setIcon(iconDefault); | |
setText(toolTip); | |
setForeground(Color.BLACK); | |
setHorizontalTextPosition(JButton.CENTER); | |
setVerticalTextPosition(JButton.CENTER); | |
setCursor(new Cursor(Cursor.HAND_CURSOR)); | |
setForeground(Color.BLACK); | |
//setVisible(true); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment