Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.event.*;
- import java.awt.Color;
- import java.util.Random;
- public class gui1 extends JFrame{
- JLabel lab;
- JButton butt;
- JButton butter;
- Actionx ac;
- JTextArea text;
- public gui1()
- {
- super("GUI NO.1");
- this.setLayout(null);
- this.setBounds(0, 0,800, 420);
- lab = new JLabel("test");
- butt = new JButton("blub");
- butter = new JButton("butter");
- text = new JTextArea("");
- ac = new Actionx();
- lab.setBounds(485, 60, 100, 20);
- butt.setBounds(400, 100, 90, 25);
- butt.addActionListener(ac);
- butter.addActionListener(ac);
- butter.setBounds(500, 100, 90, 25);
- text.setBounds(10, 10, 200, 25);
- this.add(text);
- this.add(lab);
- this.add(butt);
- this.add(butter);
- // this.setResizable(false);
- this.setVisible(true);
- }
- private class Actionx implements ActionListener, MouseMotionListener{
- Random rand = new Random();
- public void actionPerformed(ActionEvent event){
- if(event.getSource()==butt){
- int r = rand.nextInt(255);
- int g = rand.nextInt(255);
- int b = rand.nextInt(255);
- Color rgb = new Color(r,g,b);
- text.setBackground(rgb);
- }
- }
- public void mouseDragged(MouseEvent event){
- }
- public void mouseMoved(MouseEvent event){
- int x = rand.nextInt(600);
- }
- }
- //AUSFÜHRUNG
- public static void main(String[] args) {
- gui1 blub = new gui1();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement