Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import javax.swing.JButton;
- import javax.swing.JPanel;
- public class PanelZPrzyciskami extends JPanel implements ActionListener {
- /**
- *
- */
- public static final int HEIGHT = 200;
- public static final int WIDTH = 350;
- private JButton Button1;
- private JButton Button2;
- private JButton Button3;
- private JButton Button4;
- public PanelZPrzyciskami (){
- Button1 = new JButton ("Zielony");
- Button2 = new JButton ("Niebieski");
- Button3 = new JButton ("Żółty");
- Button4 = new JButton ("Zmienny");
- Button1.addActionListener(this);
- Button2.addActionListener(this);
- Button3.addActionListener(this);
- Button4.addActionListener(this);
- setLayout (new FlowLayout());
- setPreferredSize (new Dimension (WIDTH, HEIGHT));
- add (Button1);
- add (Button2);
- add (Button3);
- add (Button4);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- Object source = e.getSource();
- if (source == Button4)
- if(Button4.getText() == "Rozmiar") do
- { Button4.setText("Kolor");
- if (source==Button1)
- Button1.setSize(100, 100);
- else if (source==Button2)
- Button2.setSize(100, 100);
- else if (source == Button3)
- Button3.setSize(100, 100);}
- //public void actionPerformed1(ActionEvent f) {
- //Object source = f.getSource();
- if (source == Button4)
- if(Button4.getText() == "Kolor")
- Button4.setText("Rozmiar");
- if (source==Button1)
- Button1.setBackground(Color.GREEN);
- else if (source==Button2)
- Button2.setBackground(Color.BLUE);
- else if (source == Button3)
- Button3.setBackground(Color.YELLOW);
- }
- }}
- //public static void main(String[] args) {
- import javax.swing.JFrame;
- public class okno1 extends JFrame {
- public okno1(){
- super ("Not Hello World");
- PanelZPrzyciskami panel_z_przyciskami = new PanelZPrzyciskami();
- add (panel_z_przyciskami);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- pack();
- setVisible(true);
- }
- /**
- * @param args
- */
- //public static void main(String[] args) {
- // TODO Auto-generated method stub
- }
- public class Test2 {
- public static void main(String[] args) {
- new okno1();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement