Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Dimension;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JDialog;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- /**
- *
- * @author Professor
- */
- public class Nomes {
- static void janela() {
- String[] nomes = new String[7];
- JFrame j = new JFrame("LISTA NOMES");
- j.setSize(400, 400);
- j.setLocationRelativeTo(j);
- j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- j.setResizable(false);
- JPanel p = new JPanel();
- GridLayout layout = new GridLayout(0, 2, 30, 30);
- p.setLayout(layout);
- JLabel jlbNome = new JLabel("Digite o nome:");
- jlbNome.setHorizontalAlignment(JLabel.RIGHT);
- jlbNome.setHorizontalTextPosition(JLabel.RIGHT);
- JTextField jtxNome = new JTextField();
- jtxNome.setPreferredSize(new Dimension(50, 24));
- JButton jbtAdicionar = new JButton("Adicionar nomes");
- JButton jBtMostrar = new JButton("Mostrar nomes");
- jBtMostrar.setBounds(50, 100, 95, 30);
- jbtAdicionar.setBounds(50, 100, 95, 30);
- jbtAdicionar.addActionListener(new ActionListener() {
- Integer i = 0;
- public void actionPerformed(ActionEvent ae) {
- nomes[i]= jtxNome.getText();
- jtxNome.setText("");
- i= i+1;
- if (i==7) { jtxNome.setEnabled(false);
- } else { jtxNome.grabFocus(); }
- }
- });
- jBtMostrar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- JDialog d = new JDialog(j, "NOMES");
- JTextArea jtArea = new JTextArea("NOMES");
- jtArea.setSize(new Dimension(50, 150));
- String nomesT="";
- for (int i = nomes.length-1; i >=0; i--) {
- //System.out.println(nomes[i]);
- nomesT = nomesT + nomes[i] +"\n";
- }
- jtArea.setText(nomesT);
- d.add(jtArea);
- d.setSize(200, 150);
- d.setResizable(false);
- d.setLocationRelativeTo(j);
- d.setVisible(true);
- }
- });
- p.add(jlbNome);
- p.add(jtxNome);
- p.add(jbtAdicionar);
- p.add(jBtMostrar);
- p.setAutoscrolls(true);
- p.setPreferredSize(new Dimension(300, 200));
- j.add(p);
- j.pack();
- j.setVisible(true);
- }
- public static void main(String[] args) {
- janela();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement