Advertisement
Guest User

Java GUI Problem

a guest
Nov 27th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. public class Client extends JFrame implements ActionListener
  2. {
  3.     private JButton button;
  4.     private JTextField textfield;
  5.    
  6.     public Client()
  7.     {
  8.         super("Test");
  9.         JPanel pane = new JPanel();
  10.         pane.setLayout(new FlowLayout());
  11.        
  12.         textfield = new JTextField("TextField");
  13.         button = new JButton("Button");
  14.         button.addActionListener(this);
  15.        
  16.         pane.add(textfield);
  17.         pane.add(button);
  18.        
  19.         setContentPane(pane);
  20.     }
  21.    
  22.     public void actionPerformed(ActionEvent event)
  23.     {
  24.         Object e = event.getSource();
  25.        
  26.         if (e == button)
  27.         {
  28.             textfield.setText("Anderer Text");
  29.             try
  30.             {
  31.                 Socket client = new Socket("localhost", 12345);
  32.             }
  33.             catch (Exception ex)
  34.             {
  35.                 JOptionPane.showMessageDialog(null, "Server nicht erreichbar");
  36.             }
  37.         }
  38.     }
  39.    
  40.     public static void main(String[] args) throws UnknownHostException, IOException
  41.     {
  42.         Client frame = new Client();
  43.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  44.         frame.setSize(300, 300);
  45.         frame.setResizable(false);
  46.         frame.setVisible(true);
  47.     }
  48. }
  49.  
  50. // Ja, ich gebe zu... die GUI ist echt grausig umgesetzt...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement