Welcome to TRiBot Forums

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  
Followers 0

Importing class help...

2 posts in this topic

I have constructed a login gui for any kind of program, and its kind of long and I want to import the Gui from a separate class to prevent clutter. I need the main class to be labeled as "GuiLogin".


GUI Code:

public class lGui{	public void gui()	{	frame = new JFrame("Login");	frame.setSize(300, 150);	frame.getContentPane().setBackground(Color.LIGHT_GRAY);	frame.setLocation(300, 200);	frame.setLayout(null);	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	frame.setResizable(false);	l = new JLabel("Username: ");	l.setLocation(15, 14);	l.setSize(l.getPreferredSize());	frame.add(l);	field = new JTextField("Username");	field.setColumns(15);	field.setSize(field.getPreferredSize());	field.setBackground(Color.DARK_GRAY);	field.setForeground(Color.LIGHT_GRAY);	field.setLocation(90, 10);	field.setToolTipText("Enter User Name");	frame.add(field);	l = new JLabel("Password: ");	l.setLocation(15, 54);	l.setSize(l.getPreferredSize());	frame.add(l);	p = new JPasswordField("Password");	p.setColumns(15);	p.setSize(p.getPreferredSize());	p.setBackground(Color.DARK_GRAY);	p.setForeground(Color.LIGHT_GRAY);	p.setLocation(90, 50);	p.setToolTipText("Enter Password");	frame.add(p);	b1 = new JButton("Login");	b1.setSize(b1.getPreferredSize());	b1.setLocation(195, 78);	b1.setToolTipText("Login");	frame.add(b1);	b2 = new JButton("Cancel");	b2.setSize(b2.getPreferredSize());	b2.setLocation(95, 78);	b2.setToolTipText("Cancel");	frame.add(b2);	check = new JCheckBox("Remember me?");	check.setSize(check.getPreferredSize());	check.setLocation(120, 100);	check.setToolTipText("Remember your username for next time");	frame.add(check);	frame.setVisible(true);	}} 

Main Class code:

public class GuiLogin{	public static void main(String[] args)	{		lGui gui = new lGui();		lGui.gui();	}} 


Also need to know if I need to declare the import statements in the main class, the gui class, or both.

Same with the gui constructors.


Import Statements:

import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.awt.Color;import java.io.*; 

GUI constructors:

JFrame frame;JTextField field;JLabel l;JPasswordField p;JButton b1, b2;JCheckBox check;


**Note: I know the buttons and textfields do nothing yet, I'm currently writing the ActionListeners...I'll prob need some help with that too :P

Edited by baileyr12

Share this post

Link to post
Share on other sites

@baileyr12 If they're in the same package you should be fine, or else import it. Also if you're using eclipse it should give you the option to automatically fix it for you. 

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.