Hejsa,
En der lige kan hjælpe lidt her. Jeg har lavet et lille simpelt program hvor man kan logge ind og så kommer man ind i en menu side og så når man trykker på logud knappen. skal den logge ud og komme hen på logind siden igen. men når man trykker log ud er siden helt blank!
Håber der er en der kan hjælpe!
- import java.awt.Color;
- import java.awt.event.*;
- import javax.swing.*;
-
-
- public class Logind extends JPanel {
-
- public Logind(){
- stumper();
- }
-
- public void stumper(){
- JLabel alabel = new JLabel();
- alabel.setIcon(new ImageIcon("billed1.jpg"));
-
- JLabel blabel = new JLabel ("Brugernavn:");
- final JTextField brugernavn = new JTextField (10);
-
- JLabel clabel = new JLabel ("Kodeord:");
- final JPasswordField kodeord = new JPasswordField (10);
-
- JButton SendButton = new JButton("Log ind");
- // add the listener to the jbutton to handle the "pressed" event
- SendButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- // display/center the jdialog when the button is pressed
- String value1=brugernavn.getText();
- String value2=kodeord.getText();
- if (value1.equals("united") && value2.equals("123")) {
-
- Main.addMenu();
-
-
- }else{
- System.out.println("enter the valid username and password");
- JOptionPane.showMessageDialog(null,"Forkert Brugernavn/kodeord! \n Prøv igen!",
- "Error",JOptionPane.ERROR_MESSAGE);
- }
- }
- });
-
-
- alabel.setBounds(50, 10, 400, 100); //billed
- blabel.setBounds(150, 170, 100, 40);
- brugernavn.setBounds(250, 170, 100, 40);
- clabel.setBounds(150, 220, 100, 40);
- kodeord.setBounds(250, 220, 100, 40);
- SendButton.setBounds(200, 300, 100, 40); // x, y, h , b
-
-
- this.setLayout(null);
- this.add(alabel);
- this.add(blabel);
- this.add(clabel);
- this.add(brugernavn);
- this.add(kodeord);
- this.add(SendButton);
- SendButton.setBackground(Color.RED);
- this.setSize(500, 500);
- this.setBackground(Color.BLACK);
- this.setVisible(true);
- }
- }
- import java.awt.Color;
-
- import javax.swing.JFrame;
-
-
- public class Main {
-
- public static JFrame frame = new JFrame();
- public static Logind logind = new Logind();
- public static Menu menu = new Menu();
-
- public static void main (String[] args){
-
-
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- frame.setSize(500, 500);
-
- frame.setLayout(null);
-
- logind.setBounds(0,0, 500,500);
- frame.add(logind);
-
- frame.setVisible(true);
-
- }
-
- public static void addMenu() {
- menu.setBounds(0,0, 500,500);
- logind.setVisible(false);
- frame.add(menu);
-
- }
-
- public static void addLogind() {
- logind.setBounds(0, 0, 500, 500);
- menu.setVisible(false);
- frame.add(logind);
- }
-
-
- }
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
-
-
- public class Menu extends JPanel {
-
- public Menu(){
- Stumper();
- }
-
- public void Stumper(){
- JLabel alabel = new JLabel();
- alabel.setIcon(new ImageIcon("billed1.jpg"));
-
- JButton aButton = new JButton("Liste over spillere");
- JButton bButton = new JButton("Tilføj spiller");
- JButton cButton = new JButton("Log ud");
- // add the listener to the jbutton to handle the "pressed" event
- cButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
-
- Main.addLogind();
-
- }
- });
-
- alabel.setBounds(50, 10, 400, 100); //billed
- aButton.setBounds(170, 130, 170, 40);
- bButton.setBounds(170, 200, 170, 40);
- cButton.setBounds(170, 250,170,40);
-
- this.setLayout(null);
- this.add(alabel);
- this.add(aButton);
- aButton.setBackground(Color.RED);
- this.add(bButton);
- bButton.setBackground(Color.RED);
- this.add(cButton);
- cButton.setBackground(Color.RED);
- this.setSize(500, 500);
- this.setBackground(Color.BLACK);
- this.setVisible(true);
-
- }
-
- }