![]() |
|||
I need help with creating a Label in a JFrame
By: rekha singh | 19 Apr 2010 6:31 pm
Hi, I need help with creating a Label in a JFrame, that would say "Help" and if a user clicks on it, a picture with the Help information would display in a separate Frame. I am not sure what, if anything, I have to import, and the label code would look like this:
Commentsimports : java.awt.* + java.awt.events.* + javax.swing.* - '*' because i cant remember the specific classes but these will work fine i.e. import java.awt.*;
in the class where you create the gui (the one that extends JFrame) have -> JButton help = new JButton("help");
add(help);
and then use an actionlistener and add it to the button to listen for the click. im just trying to give you a general idea so that you can go on to sun java api and get what you need.
look for ActionEvent
ps: for the last part, id just use a JOptionPane to display the help message, but that's just me.
By: rekha singh | 19 Apr 2010
I'll also suggest you use a JButton instead of JLabel for the task, because you're not supposed to click on a label, but a button.
Create an actionListener for the button and add the following code to the listener:
try {
Runtime.getRuntime().exec("C:/..../myphoto.jpg");
} catch(IOException e) {
e.printStackTrace();
}
Does that solve it?
By: rekha singh | 19 Apr 2010
|
