Guest User

Untitled

a guest
Dec 30th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.awt.event.*;
  4.  
  5. public class NewGui {
  6.     NewGui() {
  7.    
  8.     // podstawowa deklaracja okna
  9.     JFrame window = new JFrame("First GUI app");
  10.     window.setSize(400,500);
  11.     window.setLayout(new BorderLayout());
  12.    
  13.     // panel gorny
  14.     JPanel northPanel = new JPanel();
  15.     JButton red = new JButton("RED");
  16.     red.addActionListener(new ActionListener(){
  17.         public void actionPerformed(ActionEvent e) {
  18.             northPanel.setBackground(Color.black);
  19.             repaint();
  20.         }
  21.     });
  22.     JButton blue = new JButton("BLUE");
  23.     northPanel.add(red);
  24.     northPanel.add(blue);
  25.     window.add(northPanel, BorderLayout.NORTH);
  26.    
  27.     // panel srodkowy
  28.     JPanel centerPanel = new JPanel();
  29.     window.add(centerPanel, BorderLayout.CENTER);
  30.    
  31.     // panel dolny
  32.     JPanel southPanel = new JPanel();
  33.     JButton text1 = new JButton("tekst pierwszy");
  34.     JButton text2 = new JButton("tekst drugi");
  35.     southPanel.add(text1);
  36.     southPanel.add(text2);
  37.     window.add(southPanel, BorderLayout.SOUTH);
  38.    
  39.     // podstawowa deklaracja widocznosci i zamkniecia
  40.     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  41.     window.setVisible(true);
  42.     }
  43.    
  44.    
  45.     public static void main(String args[]) {
  46.     new NewGui();          
  47.        
  48.        
  49.        
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment