Here's the code:
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Panel;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class HangmanGUI extends JPanel{
private static final long serialVersionUID = 1L;
JLabel picture;
BufferedImage image;
String word = Hangman.getWord();
int dashLength = 60;
public HangmanGUI() {
setLayout(new BorderLayout(4, 4));
//EAST_PANEL
//opens the picture and adds it to the panel
try{
image = ImageIO.read(new File("hangman.png"));
picture = new JLabel(new ImageIcon(image));
}
catch(Exception E){
System.out.println("Error");
}
Panel eastPanel = new Panel();
eastPanel.add(picture);
this.add(eastPanel, BorderLayout.EAST);
//SOUTH_PANEL
Panel southPanel = new Panel();
JPanel drawPanel = new JPanel(){
//this method is never called
public void paintComponent(Graphics g){
super.paintComponent(g);
for(int i = 0; i < word.length(); i++){
g.drawLine( (20 + (i * dashLength)), 300, (60 + (i * dashLength)), 300);
}
}
};
southPanel.add(drawPanel);
this.add(southPanel, BorderLayout.SOUTH);
}
// public void paintComponent(Graphics g){
// super.paintComponent(g);
// for(int i = 0; i < word.length(); i++){
// g.drawLine( (20 + (i * dashLength)), 300, (60 + (i * dashLength)), 300);
// }
// }
}
I have tried to add drawPanel to the main JPanel and to the southPanel. If there's anyone who could help, it would be greatly appreciated. Thanks

New Topic/Question
Reply



MultiQuote








|