Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class KnappFrame extends JFrame implements ActionListener{
- JLabel lbl;
- JButton b;
- JButton b2;
- public KnappFrame(){
- setLayout(new FlowLayout());
- JLabel lbl = new JLabel("Text, text, mera text.....");
- lbl.setFont(new Font("Times new roman", Font.ITALIC + Font.BOLD, 15));
- lbl.setForeground(Color.yellow);
- lbl.setOpaque(true);
- lbl.setBackground(Color.blue);
- b = new JButton("Blå");
- b2 = new JButton("Röd");
- add(b);
- add(b2);
- add(lbl);
- b.addActionListener(this);
- b2.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e){
- if(e.getSource() == b) {
- lbl.setText("Det funkar!!!");
- }
- if(e.getSource() == b2) {
- //lbl.setBackground(Color.red);
- }
- }
- public static void main(String[] args){
- KnappFrame f = new KnappFrame();
- f.setSize(220,200);
- f.setLocation(100,100);
- f.setTitle("Min första GUI-applikation");
- f.setDefaultCloseOperation(KnappFrame.EXIT_ON_CLOSE);
- f.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement