i have a problem with drawing in my JFrame app. I have these two functions:
Im quite new to such graphics in Java, i was wondering if someone would be kind and help me. I need to add the line on the JLabel called areaImage. I tried using some done code i found here but none worked for me. Is my code usable with some bugs? Or is it completely bad?
Please dont just post a link with some code, Im not skilled enough to understand it and then change it so it fits my app...
This one just makes the window, adds the components:
public void game (int difficulty)
{
getContentPane().removeAll();
areaImage = new JLabel ();
areaImage.setBounds (50,100,650,500);
areaImage.setForeground(Color.WHITE);
areaImage.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.BLACK));
add(areaImage);
paint (100,120,500,500, null);
info = new JLabel (" Write your answer into the text field");
info.setBounds(730,180,250,50);
info.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.BLACK));
info.setFont(new Font ("Arial", Font.PLAIN, 15));
areaImage.setForeground(Color.red);
add(info);
inputField = new JTextField("");
inputField.setBounds(810, 240, 80, 50);
add(inputField);
checkAnswer = new JButton ("Check");
checkAnswer.setBounds(750, 330, 200, 50);
checkAnswer.setContentAreaFilled(false);
checkAnswer.setOpaque(false);
checkAnswer.addActionListener(this);
checkAnswer.setFont (new Font("Arial",Font.PLAIN, 30));
add(checkAnswer);
next = new JButton ("Next");
next.setBounds(750,440,200,50);
next.setContentAreaFilled(false);
next.setOpaque(false);
next.addActionListener(this);
next.setFont (new Font("Arial",Font.PLAIN, 30));
add(next);
end= new JButton ("Exit");
end.setBounds (750,550,200,50);
end.setFont(new Font("Arial", Font.PLAIN, 30));
end.addActionListener(this);
end.setOpaque(false);
end.setContentAreaFilled(false);
add(end);
revalidate();
repaint();
}
This one is the drawing function:
private void paint (int x, int xx, int y, int yy, Graphics g)
{
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
g.drawLine(x,y,xx,yy);
Line2D lin = new Line2D.Float(100, 100, 250, 260);
g2.draw(lin);
}