Everything but JLabel is displaying
Code :
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.Toolkit;
import java.io.*;
public class RunescapeApp {
public static void main(String[] a) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new ButtonDemo());
f.setSize(550, 400);
f.setVisible(true);
}
}
class ButtonDemo extends JPanel implements ActionListener {
JTextField jtf;
public ButtonDemo() {
try {
makeGUI();
} catch (Exception exc) {
System.out.println("Can't create because of " + exc);
}
}
private void makeGUI() {
setLayout(new FlowLayout());
//THIS PART@@@@@@@@@@
ImageIcon ii=new ImageIcon("C:/Users/Jackson/Desktop/droplogger.png");
JLabel label=new JLabel(ii);
ImageIcon DragonHatchet = new ImageIcon(
"C:/Users/Jackson/Desktop/RS/Dragon_hatchet.gif");
JButton jb = new JButton(DragonHatchet);
jb.setActionCommand("Dragon Hatchet");
jb.addActionListener(this);
add(jb);
ImageIcon BerserkerRing = new ImageIcon(
"C:/Users/Jackson/Desktop/RS/Berserker_ring.gif");
jb = new JButton(BerserkerRing);
jb.setActionCommand("Berserker Ring");
jb.addActionListener(this);
add(jb);
ImageIcon WarriorRing = new ImageIcon(
"C:/Users/Jackson/Desktop/RS/Warrior_Ring.gif");
jb = new JButton(WarriorRing);
jb.setActionCommand("Warrior Ring");
jb.addActionListener(this);
add(jb);
ImageIcon ClueScroll = new ImageIcon(
"C:/Users/Jackson/Desktop/RS/Clue_scroll.gif");
jb = new JButton(ClueScroll);
jb.setActionCommand("Warrior Ring");
jb.addActionListener(this);
add(jb);
ImageIcon RuneSpear = new ImageIcon(
"C:/Users/Jackson/Desktop/RS/Rune_spear.gif");
jb = new JButton(RuneSpear);
jb.setActionCommand("Rune Spear");
jb.addActionListener(this);
add(jb);
jtf = new JTextField(15);
add(jtf);
}
public void actionPerformed(ActionEvent ae) {
jtf.setText(ae.getActionCommand());
}
}
When I run my program it only displays the 5 buttons and the text field. I've checked many times making sure the image name in the program matches with the one on my desktop. What am I doing wrong?
Re: Everything but JLabel is displaying
Indicate where in your code you add the label to the GUI.
Re: Everything but JLabel is displaying
^^
Same as Junky.
You created the JLabel, but forgot to add it to your ButtonDemo/JPanel