Advertisement
hercioneto

Exemplo Janela Java

Nov 14th, 2023
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. JFrame j = new JFrame("Janela");
  2.         j.setSize(400,400);
  3.         j.setLocationRelativeTo(j);
  4.         j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  5.        
  6.         JPanel p = new JPanel();
  7.         JLabel jLb1 = new JLabel("Digite algo: ");
  8.         JLabel jLb2 = new JLabel("");
  9.         JTextField jTx1 = new JTextField();
  10.         jTx1.setPreferredSize(new Dimension( 200, 24 ));
  11.         JButton jBt1=new JButton("Clique aqui");  
  12.         jBt1.setBounds(50,100,95,30);  
  13.         jBt1.addActionListener(new ActionListener(){
  14.        
  15.         public void actionPerformed(ActionEvent ae)
  16.           {
  17.            String texto = jTx1.getText();
  18.            jLb2.setText(texto);
  19.            
  20.         }
  21.         });
  22.                
  23.         p.add(jLb1);
  24.         p.add(jTx1);
  25.         p.add(jBt1);
  26.         p.add(jLb2);
  27.         j.add(p);
  28.         j.setVisible(true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement