

































Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!


































import javax.swing.*;
public class Formulario extends JFrame{ private JLabel label1; public Formulario() { setLayout(null); label1=new JLabel("Hola Mundo."); label1.setBounds(10,20,200,30); add(label1); }
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(10,10,400,300); formulario1.setVisible(true); } }
import java.util.Scanner;
import java.util.*;
import javax.swing.JFrame; import javax.swing.JLabel;
import javax.swing.*;
public class Formulario extends JFrame{
private JLabel label1;
public Formulario() { setLayout(null);
label1=new JLabel("Hola Mundo.");
label1=new JLabel("Hola Mundo."); label1.setBounds(10,20,200,30); add(label1); }
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(10,10,400,300); formulario1.setVisible(true); }
import javax.swing.*; public class Formulario extends JFrame{ public Formulario() { setLayout(null); }
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(10,20,400,300); formulario1.setVisible(true); } }
import javax.swing.*;
public class Formulario extends JFrame{
public Formulario() { setLayout(null); }
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(10,20,400,300); formulario1.setVisible(true); }
Problemas propuestos
import javax.swing.*; public class Formulario extends JFrame{ Formulario() { setLayout(null); }
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(0,0,1024,800); formulario1.setResizable(false); formulario1.setVisible(true); } }
import javax.swing.*;
public class Formulario extends JFrame {
private JLabel label1,label2;
public Formulario() { setLayout(null); label1=new JLabel("Sistema de Facturación."); label1.setBounds(10,20,300,30); add(label1); label2=new JLabel("Vesion 1.0"); label2.setBounds(10,100,100,30); add(label2); }
label1.setBounds(10,20,100,30); add(label1); label2=new JLabel("Verde"); label2.setBounds(10,60,100,30); add(label2); label3=new JLabel("Azul"); label3.setBounds(10,100,100,30); add(label3); }
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(0,0,300,200); formulario1.setVisible(true); } }
import javax.swing.; import java.awt.event.;
public class Formulario extends JFrame implements ActionListener { JButton boton1; public Formulario() { setLayout(null); boton1=new JButton("Finalizar"); boton1.setBounds(300,250,100,30);
add(boton1); boton1.addActionListener(this); }
public void actionPerformed(ActionEvent e) { if (e.getSource()==boton1) { System.exit(0); } }
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(0,0,450,350); formulario1.setVisible(true); } }
interface ActionListener { public void actionPerformed(ActionEvent e) { }
public class Formulario extends JFrame implements ActionListener {
Definimos un objeto de la clase JButton:
JButton boton1;
public Formulario() { setLayout(null); boton1=new JButton("Finalizar"); boton1.setBounds(300,250,100,30); add(boton1); boton1.addActionListener(this); }
boton1.addActionListener(this);
boton2=new JButton("2"); boton2.setBounds(110,100,90,30); add(boton2); boton2.addActionListener(this);
boton3=new JButton("3"); boton3.setBounds(210,100,90,30); add(boton3); boton3.addActionListener(this); }
public void actionPerformed(ActionEvent e) { if (e.getSource()==boton1) { setTitle("boton 1"); } if (e.getSource()==boton2) { setTitle("boton 2"); } if (e.getSource()==boton3) { setTitle("boton 3"); } }
public static void main(String[] ar){ Formulario formulario1=new Formulario(); formulario1.setBounds(0,0,350,200); formulario1.setVisible(true); } }
private JButton boton1,boton2,boton3;
public Formulario() { setLayout(null); boton1=new JButton("1"); boton1.setBounds(10,100,90,30); add(boton1); boton1.addActionListener(this); boton2=new JButton("2"); boton2.setBounds(110,100,90,30); add(boton2); boton2.addActionListener(this); boton3=new JButton("3"); boton3.setBounds(210,100,90,30); add(boton3); boton3.addActionListener(this); }
public void actionPerformed(ActionEvent e) { if (e.getSource()==boton1) { setTitle("boton 1"); } if (e.getSource()==boton2) { setTitle("boton 2"); } if (e.getSource()==boton3) { setTitle("boton 3"); } }
import javax.swing.; import java.awt.event.; public class Formulario extends JFrame implements ActionListener{ private JButton boton1,boton2; public Formulario() { setLayout(null); boton1=new JButton("Varón"); boton1.setBounds(10,10,100,30); boton1.addActionListener(this); add(boton1);
boton2=new JButton("Mujer"); boton2.setBounds(10,70,100,30); boton2.addActionListener(this); add(boton2); }
public void actionPerformed(ActionEvent e) { if (e.getSource()==boton1) { setTitle("Varón"); } if (e.getSource()==boton2) { setTitle("Mujer"); } }
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(0,0,130,140); formulario1.setVisible(true); } }
public class Formulario extends JFrame implements ActionListener{ private JTextField textfield1; private JLabel label1; private JButton boton1;
public Formulario() { setLayout(null); label1=new JLabel("Usuario:"); label1.setBounds(10,10,100,30); add(label1); textfield1=new JTextField(); textfield1.setBounds(120,10,150,20); add(textfield1); boton1=new JButton("Aceptar"); boton1.setBounds(10,80,100,30); add(boton1); boton1.addActionListener(this); }
public void actionPerformed(ActionEvent e) { if (e.getSource()==boton1) { String cad=textfield1.getText(); setTitle(cad); } }
Problema 2:
Programa:
import javax.swing.; import java.awt.event.; public class Formulario extends JFrame implements ActionListener{ private JTextField textfield1,textfield2; private JButton boton1;
public Formulario() { setLayout(null); textfield1=new JTextField(); textfield1.setBounds(10,10,100,30); add(textfield1); textfield2=new JTextField(); textfield2.setBounds(10,50,100,30); add(textfield2); boton1=new JButton("Sumar"); boton1.setBounds(10,90,100,30); add(boton1); boton1.addActionListener(this); }
public void actionPerformed(ActionEvent e) { if (e.getSource()==boton1) { String cad1=textfield1.getText(); String cad2=textfield2.getText(); int x1=Integer.parseInt(cad1); int x2=Integer.parseInt(cad2); int suma=x1+x2; String total=String.valueOf(suma); setTitle(total); } }
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(0,0,140,150); formulario1.setVisible(true); } }
public class Formulario extends JFrame implements ActionListener{ private JTextField textfield1,textfield2; private JButton boton1;
String cad1=textfield1.getText(); String cad2=textfield2.getText();
int x1=Integer.parseInt(cad1); int x2=Integer.parseInt(cad2);
int suma=x1+x2;
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(0,0,240,200); formulario1.setVisible(true); } }
import javax.swing.*; public class Formulario extends JFrame{ private JTextField textfield1; private JTextArea textarea1; public Formulario() { setLayout(null); textfield1=new JTextField(); textfield1.setBounds(10,10,200,30); add(textfield1); textarea1=new JTextArea(); textarea1.setBounds(10,50,400,300); add(textarea1); }
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(0,0,540,400); formulario1.setVisible(true); } }
textarea1=new JTextArea(); textarea1.setBounds(10,50,400,300); add(textarea1);
import javax.swing.*; public class Formulario extends JFrame{ private JTextField textfield1; private JScrollPane scrollpane1; private JTextArea textarea1; public Formulario() { setLayout(null); textfield1=new JTextField(); textfield1.setBounds(10,10,200,30); add(textfield1); textarea1=new JTextArea(); scrollpane1=new JScrollPane(textarea1); scrollpane1.setBounds(10,50,400,300); add(scrollpane1); }
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(0,0,540,400); formulario1.setVisible(true); } }
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(0,0,400,380); formulario1.setVisible(true); } }
String texto=textarea1.getText();
if (texto.indexOf("argentina")!=-1) { setTitle("Si contiene el texto "argentina""); } else { setTitle("No contiene el texto "argentina""); }
setTitle("Si contiene el texto "argentina"");
Problemas propuestos
mismo contenido.
import javax.swing.; import java.awt.event.; public class Formulario extends JFrame implements ActionListener{ private JScrollPane scrollpane1,scrollpane2; private JTextArea textarea1,textarea2; private JButton boton1; public Formulario() { setLayout(null); textarea1=new JTextArea(); scrollpane1=new JScrollPane(textarea1); scrollpane1.setBounds(10,10,200,140); add(scrollpane1); textarea2=new JTextArea(); scrollpane2=new JScrollPane(textarea2); scrollpane2.setBounds(220,10,200,140); add(scrollpane2); boton1=new JButton("Verificar contenidos"); boton1.setBounds(10,170,150,30); add(boton1); boton1.addActionListener(this); }
public void actionPerformed(ActionEvent e) { if (e.getSource()==boton1) { String texto1=textarea1.getText();
String texto2=textarea2.getText(); if (texto1.equals(texto2)==true) { setTitle("Los dos controles tiene el mismo texto."); } else { setTitle("Los dos controles no tiene el mismo texto."); } } }
public static void main(String[] ar) { Formulario formulario1=new Formulario(); formulario1.setBounds(0,0,500,350); formulario1.setVisible(true); } }
import javax.swing.; import java.awt.event.;
public class Formulario extends JFrame implements ItemListener{ private JComboBox combo1; public Formulario() { setLayout(null); combo1=new JComboBox(); combo1.setBounds(10,10,80,20); add(combo1); combo1.addItem("rojo"); combo1.addItem("vede");