Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- public class NewGui {
- NewGui() {
- // podstawowa deklaracja okna
- JFrame window = new JFrame("First GUI app");
- window.setSize(400,500);
- window.setLayout(new BorderLayout());
- // panel gorny
- JPanel northPanel = new JPanel();
- JButton red = new JButton("RED");
- red.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- northPanel.setBackground(Color.black);
- repaint();
- }
- });
- JButton blue = new JButton("BLUE");
- northPanel.add(red);
- northPanel.add(blue);
- window.add(northPanel, BorderLayout.NORTH);
- // panel srodkowy
- JPanel centerPanel = new JPanel();
- window.add(centerPanel, BorderLayout.CENTER);
- // panel dolny
- JPanel southPanel = new JPanel();
- JButton text1 = new JButton("tekst pierwszy");
- JButton text2 = new JButton("tekst drugi");
- southPanel.add(text1);
- southPanel.add(text2);
- window.add(southPanel, BorderLayout.SOUTH);
- // podstawowa deklaracja widocznosci i zamkniecia
- window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- window.setVisible(true);
- }
- public static void main(String args[]) {
- new NewGui();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment