Commit 4566a36c by Patryk Czarnik

Rozmowa - Nispodzianka

parent a47a3707
...@@ -4,6 +4,7 @@ import javax.swing.*; ...@@ -4,6 +4,7 @@ import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.Random;
public class Rozmowa1 { public class Rozmowa1 {
private static final Font FONT = new Font("Arial", Font.BOLD, 32); private static final Font FONT = new Font("Arial", Font.BOLD, 32);
...@@ -49,13 +50,13 @@ public class Rozmowa1 { ...@@ -49,13 +50,13 @@ public class Rozmowa1 {
panel.add(Box.createRigidArea(odstep)); panel.add(Box.createRigidArea(odstep));
// JButton guzik2 = new JButton("Niespodzianka"); JButton guzik2 = new JButton("Niespodzianka");
// guzik2.setFont(FONT); guzik2.setFont(FONT);
// guzik2.setForeground(Color.RED); guzik2.setForeground(Color.RED);
// guzik2.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30)); guzik2.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
// panel.add(guzik2); panel.add(guzik2);
//
// panel.add(Box.createRigidArea(odstep)); panel.add(Box.createRigidArea(odstep));
okno.pack(); okno.pack();
// Aby naciśnięcie guzika spowodowało rekację, do guzika trzeba przekazać "listenera", // Aby naciśnięcie guzika spowodowało rekację, do guzika trzeba przekazać "listenera",
...@@ -81,6 +82,14 @@ public class Rozmowa1 { ...@@ -81,6 +82,14 @@ public class Rozmowa1 {
powitanie.setForeground(Color.MAGENTA); powitanie.setForeground(Color.MAGENTA);
}); });
Random random = new Random();
guzik2.addActionListener(evt -> {
okno.getContentPane().setBackground(new Color(random.nextInt(0x1000000)));
int x = okno.getX() + random.nextInt(400) - 200;
int y = okno.getY() + random.nextInt(400) - 200;
okno.setLocation(x, y);
});
okno.setVisible(true); okno.setVisible(true);
System.out.println("okno wyświetlone, koniec main"); System.out.println("okno wyświetlone, koniec main");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment