Código HTML:
import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; public class Gossera extends JFrame { //Variables JRadioButton rb1, rb2; ButtonGroup bg1; JPanel p1, p2; JButton b1; JLabel l1, l2, l3, l4, l5; JComboBox cb1; JTextField tf1; JCheckBox chb1; public Gossera (String titol) { //Definim el titol, la grandaria de la pantalla, posem a null la //localizacio relativa per que sino ocupara tota la pantalla super(titol); this.setSize(253,350); this.setLocationRelativeTo(null); this.setLayout(null); l1 = new JLabel ("Gossera Municipal de Valls"); l1.setForeground(Color.blue); l1.setBounds(30, 5, 300, 30); this.add(l1); l2 = new JLabel ("Tipus animal: "); l2.setBounds(5, 50, 100, 30); this.add(l2); //Fem el combobox amb els seus items cb1 = new JComboBox (); cb1.setBounds(120, 50, 120, 30); this.add(cb1); cb1.addItem("Gos"); cb1.addItem("Gat"); cb1.addItem("Conill"); cb1.addItem("Ocell"); //Aqui acaba el combobox l3 = new JLabel ("Sexe: "); l3.setBounds(5, 100, 100, 30); this.add(l3); //Radiobutons rb1 = new JRadioButton("Mascle", true); rb2 = new JRadioButton("Femella", false); ButtonGroup bg1 = new ButtonGroup(); add(rb1); add(rb2); bg1.add(rb1); bg1.add(rb2); rb1.setBounds(80, 90, 100, 50); rb2.setBounds(80, 120, 100, 50); //Fi radiobuttons l4 = new JLabel ("Nom animal: "); l4.setBounds(5, 170, 150, 30); this.add(l4); tf1 = new JTextField (""); tf1.setBounds(100, 170, 100, 30); this.add(tf1); l5 = new JLabel ("Animal esterilitzat: "); l5.setBounds(5, 220, 150, 30); this.add(l5); chb1 = new JCheckBox ("Si"); chb1.setBounds(170, 220, 100, 30); this.add(chb1); b1 = new JButton("Visualitzar"); b1.setBounds(3, 272, 244, 50); this.add(b1); //Ho fem visible this.setVisible(true); } public class CaptarValors implements ActionListener { public void actionPerformed(ActionEvent x) { } } public static void main(String[] args) { new Gossera("Gossera"); } }