Click here to Skip to main content
15,902,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Window.Type;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class WelcomePage extends AdminLogin {

	private JFrame frame;
	private JButton btnAdmin;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					WelcomePage window = new WelcomePage();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public WelcomePage() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.getContentPane().setBackground(Color.BLUE);
		frame.setBackground(Color.BLUE);
		frame.setBounds(100, 100, 495, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);

		JLabel lblOnlineElectionManager = new JLabel(
				"Welcome To Online Election Manager");
		lblOnlineElectionManager.setForeground(Color.WHITE);
		lblOnlineElectionManager.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblOnlineElectionManager.setBounds(100, 11, 284, 47);
		frame.getContentPane().add(lblOnlineElectionManager);

		JLabel lblLoginAs = new JLabel("Login as");
		lblLoginAs.setForeground(Color.WHITE);
		lblLoginAs.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblLoginAs.setBounds(195, 84, 77, 36);
		frame.getContentPane().add(lblLoginAs);

		btnAdmin = new JButton("ADMIN");
		btnAdmin.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnAdmin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				if (e.getSource() == btnAdmin) {
					AdminLogin admin = new AdminLogin();
					frame.setVisible(false);
					admin.setVisible(true);
				}

			}
		});
		btnAdmin.setBounds(45, 192, 117, 36);
		frame.getContentPane().add(btnAdmin);

		JButton btnVoter = new JButton("VOTER");
		btnVoter.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnVoter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnVoter.setBounds(267, 192, 117, 36);
		frame.getContentPane().add(btnVoter);
	}

}


What I have tried:

I tried creating an instance of the second class "AdminLogin" which i want to move to after clicking a button on this "WelcomePage" class. When i try to run there's an error at "admin.setVisible(true)". What did i do wring?
Posted
Comments
Richard Deeming 26-Feb-18 10:36am    
Well the first thing you did wrong was to tell us "there's an error at", but not tell us what that error is.

Click "Improve question" and update your question with the full details of the error.

1 solution

Have you added setVisible method in your AdminLogin class ?
public void setVisible(boolean b){   
 }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900