ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Programación un código en JAVA


Enviado por   •  16 de Enero de 2016  •  Exámen  •  336 Palabras (2 Páginas)  •  227 Visitas

Página 1 de 2

esto es un código en JAVA

/***:

*@Programa: Ej2EjemploDibujo.java

*Descripcion: Inicia POO Manejo de objetos y eventos

*

***/

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Ej2EjemploDibujo extends JFrame

implements ActionListener {

private JButton boton;

private JPanel panel;

public static void main(String[] args) {

EjemploDibujo marco = new EjemploDibujo();

marco.setSize(420, 350);

marco.crearGUI();

marco.setVisible(true);

}

private void crearGUI() {

setDefaultCloseOperation(EXIT_ON_CLOSE);

Container ventana = getContentPane();

ventana.setLayout(new FlowLayout() );

panel = new JPanel();

panel.setPreferredSize(new Dimension(250, 150));

panel.setBackground(Color.white);

ventana.add(panel);

boton = new JButton("Haga clic");

ventana.add(boton);

boton.addActionListener(this);

}

public void actionPerformed(ActionEvent event) {

Graphics papel = panel.getGraphics();

papel.drawLine(0, 0, 100, 100);

papel.drawLine(5, 10, 100, 100);

}

}

/***:

*@Programa: Ej1EjemploDibujo.java

*Descripcion: Inicia POO Manejo de objetos y eventos

*

***/

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Ej1EjemploDibujo extends JFrame

implements ActionListener {

private JButton boton;

private JPanel panel;

public static void main(String[] args) {

EjemploDibujo marco = new EjemploDibujo();

marco.setSize(420, 350);

marco.crearGUI();

marco.setVisible(true);

}

private void crearGUI() {

setDefaultCloseOperation(EXIT_ON_CLOSE);

Container ventana = getContentPane();

ventana.setLayout(new FlowLayout() );

panel = new JPanel();

panel.setPreferredSize(new Dimension(250, 150));

panel.setBackground(Color.white);

ventana.add(panel);

boton = new JButton("Haga clic");

ventana.add(boton);

boton.addActionListener(this);

}

public void actionPerformed(ActionEvent event) {

Graphics papel = panel.getGraphics();

papel.drawLine(0, 0, 100, 100);

}

}

...

Descargar como (para miembros actualizados) txt (2 Kb) pdf (52 Kb) docx (10 Kb)
Leer 1 página más »
Disponible sólo en Clubensayos.com