Bom dia!
Eu estou com um Problema em adicionar um JTextField em um JPanel. Na minha classe Principal eu instanciei um JFrame e a ele adicionei um JPanel.
Na classe DrawPanel (extends JPanel) eu estou tentado adicionar um JTextField, mas nao consigo.
Se poderem me ajudar desde já agradeço;
import java.awt.Color;
import javax.swing.JFrame;
public class Principal {
public static void main (String[] args){
JFrame tela = new JFrame();
tela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tela.setSize(1200, 700);
tela.getContentPane().setBackground(Color.red);
tela.setVisible(true);
tela.setLayout(null);
tela.setTitle("integral");
DrawPanel grafico = new DrawPanel();
grafico.setLocation(10, 10);
CrtlPanel comando = new CrtlPanel();
comando.setLocation(10, 470);
tela.add(grafico);
tela.add(comando);
}
}
////////***********///////////////////
import java.awt.Color;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class DrawPanel extends JPanel{
private JTextField teste;
public DrawPanel() {
setSize(1160,450);
setVisible(true);
setBackground(Color.green);
setLayout(null);
teste = new JTextField("digite");
add(teste);
teste.setSize(20, 20);
teste.setLocation(30, 30);
teste.setVisible(true);
}
}