DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

JAVA GUI

01.20.2012
| 3047 views |
  • submit to reddit
        // GUI

package gui;

import java.awt.*;

import javax.swing.*;

import lytter.Lytter;

public class Gui {
	private JFrame frame = new JFrame("Hoved");

	private Lytter l;

	private JButton b5;

	private JButton b4;

	private JButton b3;

	private JButton b2;

	private JButton b1;

	private JTextField felt;

	private JTextField felt1;

	public Gui(){

		l=new Lytter();
		frame.setLayout(new FlowLayout());
		frame.setSize(new Dimension(300, 300));
		frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);

		//initialiser knappene
		b1 = new JButton("Ansatt");
		b2 = new JButton("Kunde");
		b3 = new JButton("Logg inn");
		b4 = new JButton("Set timer");
		b5 = new JButton("Kjøp varer");
		felt = new JTextField("Skriv inn Brukernavn");
		felt1 = new JTextField("Skriv inn Passord");

		//legger til lytter til på knappene
		b1.addActionListener(l);
		b2.addActionListener(l);
		b3.addActionListener(l);
		b4.addActionListener(l);
		b5.addActionListener(l);

		//legger knappene og tekstfeltene til JFramen
		frame.add(b1);
		frame.add(b2);
		frame.add(b3);
		frame.add(b4);
		frame.add(b5);
		frame.add(felt);
		frame.add(felt1);

		//Setter visualiteten til komponentene og containeren
		b1.setVisible(true);
		b2.setVisible(true);
		b3.setVisible(false);
		b4.setVisible(false);
		b5.setVisible(false);
		felt.setVisible(false);
		felt1.setVisible(false);
		frame.setVisible(true);
	}
	//metode for å skjule knapper 1, 2 og vise knapper3 og tekstfelt 1 og 2 
	public void ansatt(){
		b1.setVisible(false);
		b2.setVisible(false);
		b3.setVisible(true);
		felt.setVisible(true);
		felt1.setVisible(true);
	}

}

    

Comments

Snippets Manager replied on Sat, 2012/01/21 - 9:55am

public void addActionListener(ActionListener l){ //legger til lytter til på knappene b1.addActionListener(l); b2.addActionListener(l); b3.addActionListener(l); b4.addActionListener(l); b5.addActionListener(l); }