Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.event.*;
  3. import java.awt.Color;
  4. import java.util.Random;
  5.  
  6. public class gui1 extends JFrame{
  7.  
  8.    
  9.    
  10.     JLabel lab;
  11.     JButton butt;
  12.     JButton butter;
  13.     Actionx ac;
  14.     JTextArea text;
  15.    
  16.    
  17.    
  18.     public gui1()
  19.     {
  20.         super("GUI NO.1");
  21.         this.setLayout(null);
  22.         this.setBounds(0, 0,800, 420);
  23.         lab = new JLabel("test");
  24.         butt = new JButton("blub");
  25.         butter = new JButton("butter");
  26.         text = new JTextArea("");
  27.         ac = new Actionx();
  28.         lab.setBounds(485, 60, 100, 20);
  29.         butt.setBounds(400, 100, 90, 25);
  30.         butt.addActionListener(ac);
  31.         butter.addActionListener(ac);
  32.         butter.setBounds(500, 100, 90, 25);
  33.         text.setBounds(10, 10, 200, 25);
  34.         this.add(text);
  35.         this.add(lab);
  36.         this.add(butt);
  37.         this.add(butter);
  38.     //  this.setResizable(false);
  39.         this.setVisible(true);
  40.        
  41.     }
  42.    
  43.    
  44.     private class Actionx implements ActionListener, MouseMotionListener{
  45.        
  46.         Random rand = new Random();
  47.        
  48.        
  49.         public void actionPerformed(ActionEvent event){
  50.            
  51.             if(event.getSource()==butt){
  52.                 int r = rand.nextInt(255);
  53.                 int g = rand.nextInt(255);
  54.                 int b = rand.nextInt(255);
  55.                
  56.                 Color rgb = new Color(r,g,b);
  57.                 text.setBackground(rgb);               
  58.             }
  59.         }
  60.         public void mouseDragged(MouseEvent event){
  61.                
  62.         }
  63.         public void mouseMoved(MouseEvent event){
  64.             int x = rand.nextInt(600);
  65.         }
  66.                
  67.         }      
  68.    
  69.        
  70.     //AUSFÜHRUNG
  71.     public static void main(String[] args) {
  72.        
  73.         gui1 blub = new gui1();
  74.        
  75.     }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement