-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainFrame.java
executable file
·181 lines (136 loc) · 4.85 KB
/
MainFrame.java
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package MP;
/**
* @(#)MainFrame.java
*
*
* @author
* @version 1.00 2007/5/3
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import javax.imageio.*;
public class MainFrame extends JFrame{
private MainFrame MFrame;
public ToolBar Tbar;
private GridBagLayout esquema;
private GridBagConstraints restriccion;
private JDesktopPane jdpDesktop;
public JMenu Archivo;
public JMenuBar MenuArchivo;
public JMenuItem Nuevo, cerrar, guardar;
public JButton Brehacer, Bdeshacer, Bguardar, Bnuevo;
public JPanel Pbotones;
private int x, y;
public Lienzo lienzo;
private FileDialog file;
private Dialog saveDialog = new Dialog(this);
private MediaTracker media;
private Image imagen;
public MainFrame() {
super ("Art Creator");
MFrame = this;
setExtendedState(JFrame.MAXIMIZED_BOTH);
graficos();
setVisible(true);
setResizable(false);
Image logo;
logo = Toolkit.getDefaultToolkit().createImage("logo.gif");
setIconImage(logo);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void graficos (){
guardar_hand guardarImagen = new guardar_hand();
Nuevo = new JMenuItem();
Nuevo.setText("Nuevo");
Nuevo.addActionListener(new nuevo_hand());
cerrar = new JMenuItem();
cerrar.setText("Cerrar");
cerrar.addActionListener(new cerrar_hand());
guardar = new JMenuItem();
guardar.setText("Guardar");
guardar.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
guardar.setMnemonic('S');
guardar.addActionListener(guardarImagen);
Archivo = new JMenu();
Archivo.setText("Archivo");
Archivo.add(Nuevo);
Archivo.addSeparator();
Archivo.add(guardar);
Archivo.addSeparator();
Archivo.add(cerrar);
MenuArchivo=new JMenuBar();
MenuArchivo.add(Archivo);
setJMenuBar(MenuArchivo);
jdpDesktop = new JDesktopPane();
jdpDesktop.setBackground(new Color(196,196,196));
setContentPane(jdpDesktop);
esquema = new GridBagLayout();
restriccion= new GridBagConstraints();
restriccion.fill = GridBagConstraints.HORIZONTAL;
setLayout(new BorderLayout());
Pbotones = new JPanel();
Pbotones.setLayout(esquema);
Bguardar = new JButton (new ImageIcon("save.png"));
Bguardar.addActionListener(guardarImagen);
Bnuevo = new JButton (new ImageIcon("new.png"));
Bnuevo.addActionListener(new nuevo_hand());
Bguardar.setBackground(new Color(210, 210, 210));
Bnuevo.setBackground(new Color(210, 210, 210));
Tbar = new ToolBar();
agregarComponente( Bnuevo , 0, 0, 1, 1, Pbotones );
agregarComponente( Bguardar , 0, 1, 1, 1, Pbotones );
JPanel panelNorte =new JPanel();
panelNorte.setLayout(new BorderLayout());
panelNorte.add(Pbotones, BorderLayout.WEST);
add(panelNorte, BorderLayout.NORTH);
add(Tbar, BorderLayout.WEST);
}
private void agregarComponente( Component componente,
int fila, int columna,
int anchura, int altura, Container con){
restriccion.gridx = columna;
restriccion.gridy = fila;
restriccion.gridwidth = anchura;
restriccion.gridheight = altura;
esquema.setConstraints( componente, restriccion );
if (con != null)
con.add( componente );
}//END: agregarComponente
public void exitInternalFrame(){
this.setVisible(false);
}
private class nuevo_hand implements ActionListener{
public void actionPerformed(ActionEvent evento){
try{
lienzo = new Lienzo(MFrame, Tbar);
}
catch(Exception e){
System.out.println(e);
}
}
}
private class guardar_hand implements ActionListener{
public void actionPerformed(ActionEvent evento){
try {
file = new FileDialog(saveDialog , "Guardar", FileDialog.SAVE);
file.setVisible(true);
File a = new File(file.getDirectory()+ file.getFile()+".png");
ImageIO.write(lienzo.getImage(), "png", a);
}
catch (Exception ex) {
System.out.println (ex);
}
}
}
private class cerrar_hand implements ActionListener{
public void actionPerformed(ActionEvent e){
try{
System.exit(0);
}
catch (Exception ex) {
}
}
}
}