-
Notifications
You must be signed in to change notification settings - Fork 0
/
TamanoLienzo.java
executable file
·99 lines (79 loc) · 2.65 KB
/
TamanoLienzo.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
/**
* @(#)TamanoLienzo.java
*
*
* @author
* @version 1.00 2007/5/3
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class TamanoLienzo extends JDialog{
private JTextField ancho, alto;
private JButton aceptar;
private JLabel Lancho, Lalto;
public int x, y;
public TamanoLienzo(Lienzo lienzo) {
super(lienzo,true);
setSize(230,140);
getContentPane();
setLayout(null);
Lancho = new JLabel("Ancho");
Lancho.setBounds(20,10,50,20);
add(Lancho);
ancho = new JTextField();
ancho.setBounds(100,10,70,20);
add(ancho);
Lalto = new JLabel("Alto");
Lalto.setBounds(20,35,50,20);
add(Lalto);
alto = new JTextField();
alto.setBounds(100,35,70,20);
add(alto);
aceptar = new JButton("Aceptar");
aceptar.setBounds(75,70,80,30);
aceptar.addActionListener(new aceptar_hand(lienzo));
add(aceptar);
setResizable(false);
cuadrarFrame();
setVisible(true);
}
private void cuadrarFrame(){
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension dialogSize = getSize();
if (dialogSize.height > screen.height) {
dialogSize.height = screen.height;
}
if (dialogSize.width > screen.width) {
dialogSize.width = screen.width;
}
setLocation((screen.width - dialogSize.width)/3 , (screen.height - dialogSize.height)/3);
}
private class aceptar_hand implements ActionListener{
public Lienzo otro;
public aceptar_hand(Lienzo lienzo){
otro = lienzo;
}
public void actionPerformed(ActionEvent evento){
try{
x = Integer.parseInt(ancho.getText());
y = Integer.parseInt(alto.getText());
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
if ( x <= screen.width-300 && y <= screen.height-120){
otro.setBounds (300,80,x,y);
}
else{
JOptionPane.showMessageDialog(null,"tamaño demaciado grande","CAMBIO",JOptionPane.INFORMATION_MESSAGE);
otro.setBounds (300,80,screen.width-300,screen.height-120);
}
otro.setMaximumSize(new Dimension(screen.width-300,screen.height-120));
otro.setVisible(true);
dispose();
}
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null,"alguno de los parametros digitados no es valido \n solo valores enteros y positivos","ERROR",JOptionPane.ERROR_MESSAGE);
}
}
}
}