Senhor(es)(as), procurei no forum porém não tive a felicidade de achar algo pra me ajudar… Estou tentando algo simples, porém não sei onde estou errando na minha chamada, estou tentando traçar uma reta, com o DrawLine, porém, naum sei o pq esta gerando este o erro.
public void paint(Graphics g)
{
int x=Integer.parseInt(jtX.getText());
int y=Integer.parseInt(jtY.getText());
int xx=Integer.parseInt(jtXX.getText());
int yy=Integer.parseInt(jtYY.getText());
g.drawLine(x,y,xx,yy); // DA ERRO NA HORA DA CHAMADA
jfF.repaint();
}
public void actionPerformed(ActionEvent evento) {
if (evento.getActionCommand().equals("Desenhar")) {
Graphics g = null;
paint(g);
}
}
Se alguma alma caridosa ou não poder me ajudar, desde já agradeço.
Abaixo segue o código completo.
package arvore;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class DLinha extends JFrame implements ActionListener {
public JFrame jfF;
public JButton jbInicio;
public JLabel jlX,jlXX,jlY,jlYY;
public JTextField jtX,jtXX,jtY,jtYY;
public DLinha()
{
jfF = new JFrame("");
jfF.setBounds(0,0,700,700);
jfF.setLayout(null);
jbInicio = new JButton("Desenhar");
jbInicio.setBounds(600,5,90,25);
jfF.add(jbInicio);
jbInicio.setActionCommand("Desenhar");
jbInicio.addActionListener(this);
jlX= new JLabel("Posição X");
jlX.setBounds(10,5,60,25);
jfF.add(jlX);
jtX= new JTextField();
jtX.setBounds(75,5,50,25);
jfF.add(jtX);
jlY= new JLabel("Posição Y");
jlY.setBounds(135,5,60,25);
jfF.add(jlY);
jtY= new JTextField();
jtY.setBounds(200,5,50,25);
jfF.add(jtY);
jlXX= new JLabel("Posição XX");
jlXX.setBounds(255,5,65,25);
jfF.add(jlXX);
jtXX= new JTextField();
jtXX.setBounds(325,5,50,25);
jfF.add(jtXX);
jlYY= new JLabel("Posição YY");
jlYY.setBounds(380,5,65,25);
jfF.add(jlYY);
jtYY= new JTextField();
jtYY.setBounds(445,5,50,25);
jfF.add(jtYY);
jfF.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
jfF.setVisible(true);
}
public void paint(Graphics g)
{
int x=Integer.parseInt(jtX.getText());
int y=Integer.parseInt(jtY.getText());
int xx=Integer.parseInt(jtXX.getText());
int yy=Integer.parseInt(jtYY.getText());
g.drawLine(x,y,xx,yy); // DA ERRO NA HORA DA CHAMADA
jfF.repaint();
}
public void actionPerformed(ActionEvent evento) {
if (evento.getActionCommand().equals("Desenhar")) {
Graphics g = null;
paint(g);
}
}
public static void main (String[] arg)
{
DLinha dl=new DLinha();
}
}