// VENTANA CON COMPONENTES import java.awt.event.*; import javax.swing.*; import java.awt.*; public class Ventana extends JFrame { JButton OK = new JButton("OK"); JLabel LX = new JLabel("X"); JLabel LY = new JLabel("Y"); JTextField TF_X, TF_Y; int X=0, Y=0; JPanel Grafico, Control; public static void main(String ARGS[]) { new Ventana(); } public Ventana() { this.setLayout( null ); this.setBounds(100, 100, 600, 600); this.setVisible(true); Control = new JPanel(); this.add(Control); Control.setLayout(null); Control.setBackground(Color.blue); Control.setBounds(10, 500, 500, 50); Control.add(OK); OK.setBounds(400, 10, 100, 30); OK.addActionListener(new EVENTO()); TF_X = new JTextField(); TF_Y = new JTextField(); Control.add(TF_X); TF_X.setBounds(10, 10, 100, 30); Control.add(TF_Y); TF_Y.setBounds(150, 10, 100, 30); Grafico = new JPanel(); this.add(Grafico); Grafico.setLayout(null); Grafico.setBackground(Color.yellow); Grafico.setBounds(1, 1, 598, 450); } protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) System.exit(0); } public void paint(Graphics G) { G.setColor(Color.yellow); G.fillRect(0, 0, 598, 450); G.setColor(Color.black); G.drawLine(X, Y, X, Y); } class EVENTO implements ActionListener { public void actionPerformed(ActionEvent e) { X = Integer.parseInt(TF_X.getText()); Y = Integer.parseInt(TF_Y.getText()); repaint(); } } }