Como posso colocar junto uma figura, por exemplo, usando drawRect e um JButton dentro de um JFrame ?
No código abaixo, o botão só aparece quando eu clico na area onde ele foi criado:
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JButton;
/*
- Created on 27/10/2004
- TODO To change the template for this generated file go to
- Window - Preferences - Java - Code Style - Code Templates
*/
/**
-
@author rubens
-
TODO To change the template for this generated type comment go to
-
Window - Preferences - Java - Code Style - Code Templates
*/
public class Janela extends JFrame {private javax.swing.JPanel jContentPane = null;
private JButton jButton1 = null;
/**- This method initializes jButton1
-
@return javax.swing.JButton
/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
}
return jButton1;
}
public static void main(String[] args) {
Janela j = new Janela();
j.setVisible(true);
}
/* - This is the default constructor
/
public Janela() {
super();
initialize();
}
/* - This method initializes this
-
@return void
/
private void initialize() {
this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
this.setSize(300,200);
this.setContentPane(getJContentPane());
this.setTitle(“JFrame”);
}
/* - This method initializes jContentPane
-
@return javax.swing.JPanel
*/
private javax.swing.JPanel getJContentPane() {
if(jContentPane == null) {
jContentPane = new javax.swing.JPanel();
jContentPane.setLayout(new java.awt.BorderLayout());
jContentPane.add(getJButton1(), java.awt.BorderLayout.EAST);
}
return jContentPane;
}
public void paint (Graphics g) {
g.drawRect(10,23,100,100);
}
}