I am new to java and I am working through "Java How to Program - Third Edition" programming book I have "Forte for Java 4 - Community Edition" installed and everything was working fine until I got to chapter 12 and started working with Icon and ImageIcon each app that I write from the book compiles fine and runs but without the Icon(picture) the first app was testing JLabels and using new JLabel("String here", Iconpichere, postitionoftext) - that worked but now picture now I have this one testing JButtons and it compiles fine runs fine but - Guess what? NO ICON, can some one please give me a clue here? (God, I love Visual Basic)
Here is the Code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
* @author administrator
*/
public class ButtonTest extends JFrame {
private JButton plainButton;
private JButton fancyButton;
/** Creates a new instance of ButtonTest */
public ButtonTest() {
super("Testing Buttons"
;
Container c = getContentPane();
c.setLayout(new FlowLayout());
// create buttons
plainButton = new JButton("Plain Button"
;
c.add(plainButton);
Icon bug1 = new ImageIcon("myIcona.gif"
;
Icon bug2 = new ImageIcon("myIcona2.gif"
;
fancyButton = new JButton("Fancy Button", bug1);
fancyButton.setRolloverIcon(bug2);
c.add(fancyButton);
// Create an instance of inner class ButtonHandler
// to use for button event handling
ButtonHandler handler = new ButtonHandler();
fancyButton.addActionListener(handler);
plainButton.addActionListener(handler);
setSize(275, 100);
show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ButtonTest app = new ButtonTest();
app.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
}
// inner class for button event handling
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null, "You pressed: "
+ e.getActionCommand());
}
}
}
Here is the Code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
* @author administrator
*/
public class ButtonTest extends JFrame {
private JButton plainButton;
private JButton fancyButton;
/** Creates a new instance of ButtonTest */
public ButtonTest() {
super("Testing Buttons"
Container c = getContentPane();
c.setLayout(new FlowLayout());
// create buttons
plainButton = new JButton("Plain Button"
c.add(plainButton);
Icon bug1 = new ImageIcon("myIcona.gif"
Icon bug2 = new ImageIcon("myIcona2.gif"
fancyButton = new JButton("Fancy Button", bug1);
fancyButton.setRolloverIcon(bug2);
c.add(fancyButton);
// Create an instance of inner class ButtonHandler
// to use for button event handling
ButtonHandler handler = new ButtonHandler();
fancyButton.addActionListener(handler);
plainButton.addActionListener(handler);
setSize(275, 100);
show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ButtonTest app = new ButtonTest();
app.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
}
// inner class for button event handling
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null, "You pressed: "
+ e.getActionCommand());
}
}
}