Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Chi vuol essere informatico - Getname.java

Getname.java

Caricato da: Bonny
Scarica il programma completo

  1. package quizzone;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import javax.swing.*;
  7.  
  8. public class Getname extends JFrame {
  9.  
  10.     private JButton start = new JButton("Start");
  11.     private JLabel d = new JLabel();
  12.     public JTextField nome = new JTextField();
  13.  
  14.     public Getname() {
  15.  
  16.         super("Name");
  17.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  18.  
  19.         d.setText("Inserisci il tuo nome");
  20.  
  21.         d.setFont(new Font("Arial", Font.BOLD, 18));
  22.         nome.setBackground(Color.YELLOW);
  23.         nome.setFont(new Font("Arial", Font.BOLD, 14));
  24.         this.getContentPane().add(d, "North");
  25.         this.getContentPane().add(nome, "Center");
  26.         this.getContentPane().add(start, "South");
  27.         this.getContentPane().setBackground(Color.red);
  28.  
  29.         pack();
  30.         setResizable(false);
  31.         setVisible(true);
  32.         setLocation(460, 240);
  33.  
  34.         start.addActionListener(
  35.                 new ActionListener() {
  36.  
  37.                     public void actionPerformed(ActionEvent event) {
  38.  
  39.                         if (!nome.getText().equals("")) {
  40.  
  41.                             new Myframe(nome.getText());
  42.                             setVisible(false);
  43.                         }
  44.                     }
  45.                 });
  46.     }
  47. }