- import javax.swing;
-
import java.awt.Color;
-
import java.awt.event.ActionListener;
-
import java.awt.event.ActionEvent;
-
-
public class TextFieldExample {
-
-
JPanel textPanel, panelForTextFields, completionPanel;
-
JLabel titleLabel, usernameLabel, passwordLabel, userLabel, passLabel;
-
JTextField usernameField, loginField;
-
JButton loginButton;
-
-
public JPanel createContentPane (){
-
-
JPanel totalGUI = new JPanel();
-
totalGUI.setLayout(null);
-
-
titleLabel = new JLabel("Login Screen");
-
titleLabel.setLocation(0,0);
-
titleLabel.setSize(290, 30);
-
titleLabel.setHorizontalAlignment(0);
-
totalGUI.add(titleLabl);
-
-
-
textPanel = new JPanel();
-
textPanel.setLayout(null);
-
textPanel.setLocation(10, 35);
-
textPanel.setSize(70, 80);
-
//totalGUI.add(textPanel);
-
-
-
usernameLabel = new JLabel("Username");
-
usernameLabel.setLocation(0, 0);
-
usernameLabel.setSize(70, 40);
-
usernameLabel.setHorizontalAlignment(4);
-
textPanel.add(usernameLabel);
-
-
-
passwordLabel = new JLabel("Password");
-
passwordLabel.setLocation(0, 40);
-
passwordLabel.setSize(70, 40);
-
passwordLabel.setHorizontalAlignment(4);
-
textPanel.add(passwordLabel);
-
-
-
panelForTextField = new JPanel();
-
panelForTextFields.setLayout(null);
-
panelForTextFields.setLocation(110, 40);
-
panelForTextFields.setSize(100, 70);
-
totalGUI.add(panelForTextFields);
-
-
-
usernameField = new JTextField(8);
-
usernameField.setLocation(0, 0);
-
usernameField.setSize(100, 30);
-
panelForTextFields.add(usernameField);
-
-
-
loginField = new JTextField(8);
-
loginField.setLocation(0, 40);
-
loginField.setSize(100, 30);
-
panelForTextFields.add(loginField);
-
-
-
completionPanel = new JPanel();
-
completionPanel.setLayout(null);
-
completionPanel.setLocation(240, 35);
-
completionPanel.setSize(70, 80);
-
totalGUI.add(completionPanel);
-
-
-
userLabel = new JLabel("Wrong");
-
userLabel.setForeground(Color.red);
-
userLabel.setLocation(0, 0);
-
userLabel.setSize(70, 40);
-
completionPanel.add(userLabel);
-
-
-
passLabel = new JLabel("Wrong");
-
passLabel.setForeground(Color.red);
-
passLabel.setLocation(0, 40);
-
passLabel.setSize(70, 40);
-
completionPanel.add(passLabel);
-
-
-
loginButton = new JButton("Login");
-
loginButton.setLocation(130, 120);
-
loginButton.setSize(80, 30);
-
loginButton.addActionListener();
-
totalGUI.add(loginButton);
-
-
totalGUI.setOpaque(true);
-
return totalGUI;
-
}
-
-
// With this action performed, we simply check to see if the username and
-
// password match "Bob" as the username and "Robert" as the password.
-
// If they do, we set the labels ajacent to them to "Correct!" and color
-
// them green.
-
// At the end, we check if both labels are green. If they are, we set the
-
// screen to be 'Logging In'.
-
-
public void actionPerformed(ActionEvent e ) {
-
-
if(e.getSource() == loginButton)
-
{
-
if(usernameField.getText().trim().compareTo("Bob") == 0)
-
{
-
userLabel.setForeground(Color.green);
-
userLabel.setText("Correct!");
-
}
-
else
-
{
-
userLabel.setForeground(Color.red);
-
userLabel.setText("Wrong!");
-
}
-
-
if(loginField.getText().trim().compareTo("Robert") == 0)
-
{
-
passLabel.setForeground(Color.green);
-
passLabel.setText("Correct!");
-
}
-
else
-
{
-
passLabel.setForeground(Color.red);
-
passLabel.setText("Wrong!");
-
}
-
-
if((userLabel.getForeground() == Color.green)
-
&& (passLabel.getForeground() == Color.green))
-
{
-
titleLabel.setText("Logging in....");
-
loginButton.setEnabled(false);
-
}
-
}
-
}
-
-
-
private static void createAndShowGUI() {
-
-
JFrame.setDefaultLookAndFeelDecorated(true);
-
JFrame frame = new JFrame("[=] JTextField of Dreams [=]");
-
-
TextFieldExample demo = new TextFieldExample();
-
frame.setContentPane(demo.createContentPane());
-
-
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
frame.setSize(310, 200);
-
frame.setVisible(true);
-
}
-
-
public static void main(String args[]) {
-
//Schedule a job for the event-dispatching thread:
-
//creating and showing this application's GUI.
-
SwingUtilities.invokeLater(new Runnable() {
-
public void run() {
-
createAndShowGUI();
-
-
}
-
}
-
}
-
}
-
heres the error:
--------------------Configuration: <Default>--------------------
C:\Users\RN3\Desktop\closet sale\TextFieldExample.java:161: ')' expected
}
^
C:\Users\RN3\Desktop\closet sale\TextFieldExample.java:163: reached end of file while parsing
}
Process completed.
any one can help guys? thanks
1 1400
James,
You're missing a closing parenthesis after the closing brace on line 160.
Cheers!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Marian Jancar |
last post by:
Hi,
Is there a module for parsing spec files available?
Marian
--
--
Best Regards,
|
by: Willem Ligtenberg |
last post by:
I decided to use SAX to parse my xml file.
But the parser crashes on:
File "/usr/lib/python2.3/site-packages/_xmlplus/sax/handler.py", line 38, in fatalError
raise exception...
|
by: Cigdem |
last post by:
Hello,
I am trying to parse the XML files that the user selects(XML files are
on anoher OS400 system called "wkdis3"). But i am permenantly getting
that error:
Directory0: \\wkdis3\ROOT\home...
|
by: sunil |
last post by:
I am creating a XML document which opens fine in IE. Implies MSXML
thinks it is a well formed document.
But when I try to load this document in VB.net using the following
code
Dim doc As New...
|
by: Christoph Bisping |
last post by:
Hello!
Maybe someone is able to give me a little hint on this:
I've written a vb.net app which is mainly an interpreter for specialized
CAD/CAM files.
These files mainly contain simple movement...
|
by: .Net Sports |
last post by:
In VB.net, I'm trying to do a couple of things in a couple of different
blocks of code. I need to take the first 25 characters of a text file,
then append at the end some ellipses and a MORE link...
|
by: Thomas Kowalski |
last post by:
Hi,
I have to parse a plain, ascii text file (on local HD). Since the file
might be many millions lines long I want to improve the efficiency of
my parsing process. The resulting data structure...
|
by: Ricardo Vazquez |
last post by:
I'm writing log information into a file (via StreamWriter).
When it reached a 4GB size, my MFC/C++ code copied that file to another
name, truncated its length to 0 (CFile::SetLength(0)), and...
|
by: DjLethal |
last post by:
Hey Guys.I am a newbie on Perl.And I have a question about file parsing by perl.
I have a log file which contains reports about a communication machine.I need to take some of the reports from the...
|
by: Felipe De Bene |
last post by:
I'm having problems parsing an HTML file with the following syntax :
<TABLE cellspacing=0 cellpadding=0 ALIGN=CENTER BORDER=1 width='100%'>
<TH BGCOLOR='#c0c0c0' Width='3%'>User ID</TH>
<TH...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |