Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class KnappFrame extends JFrame implements ActionListener{
  6.  
  7. JLabel lbl;
  8. JButton b;
  9. JButton b2;
  10.  
  11. public KnappFrame(){
  12. setLayout(new FlowLayout());
  13. JLabel lbl = new JLabel("Text, text, mera text.....");
  14. lbl.setFont(new Font("Times new roman", Font.ITALIC + Font.BOLD, 15));
  15. lbl.setForeground(Color.yellow);
  16. lbl.setOpaque(true);
  17. lbl.setBackground(Color.blue);
  18. b = new JButton("Blå");
  19. b2 = new JButton("Röd");
  20. add(b);
  21. add(b2);
  22. add(lbl);
  23. b.addActionListener(this);
  24. b2.addActionListener(this);
  25. }
  26.  
  27. public void actionPerformed(ActionEvent e){
  28. if(e.getSource() == b) {
  29. lbl.setText("Det funkar!!!");
  30. }
  31. if(e.getSource() == b2) {
  32. //lbl.setBackground(Color.red);
  33. }
  34. }
  35.  
  36.  
  37. public static void main(String[] args){
  38. KnappFrame f = new KnappFrame();
  39. f.setSize(220,200);
  40. f.setLocation(100,100);
  41. f.setTitle("Min första GUI-applikation");
  42. f.setDefaultCloseOperation(KnappFrame.EXIT_ON_CLOSE);
  43. f.setVisible(true);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement