
No consigo que se dibuje en la ventana de la clase Principal el JPanel de la clase Dibuja
Publicado por Rober (2 intervenciones) el 16/12/2013 18:04:06
Buenas, estoy intentando apreder algo de java y me quedé atascado, agradeceria me puedieran ayudar.
No consigo que se dibuje en la ventana de la clase Principal el JPanel de la clase Dibuja.
Agradeceria vuestros comentarios.
Un saludo.
No consigo que se dibuje en la ventana de la clase Principal el JPanel de la clase Dibuja.
Agradeceria vuestros comentarios.
Un saludo.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Principal {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Principal window = new Principal();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Principal() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 700, 700);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenu mnPrincipal = new JMenu("Principal");
menuBar.add(mnPrincipal);
JMenuItem mntmDibuja = new JMenuItem("Dibuja");
mntmDibuja.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Dibuja dibujo = new Dibuja();
frame.add(dibujo);
}
});
mnPrincipal.add(mntmDibuja);
JMenuItem mntmSalir = new JMenuItem("Salir");
mntmSalir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
mnPrincipal.add(mntmSalir);
}
}
/////////////////////////////////////
import javax.swing.*;
import java.awt.*;
public class Dibuja extends JPanel {
@Override
public void paintComponent ( Graphics g )
{
super.paintComponent( g );
g.fillOval( 10, 10, 100, 100 ); // dibuja un círculo
g.setColor(Color.BLUE);
g.fillRect(200, 200, 100, 100);
} // fin del método paintComponent
}// Fin de la clase DibujaPerfil
Valora esta pregunta


0