Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7785691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:17:48+00:00 2026-06-01T20:17:48+00:00

This is a login form for a slot machine game which will evoke a

  • 0

This is a login form for a slot machine game which will evoke a "NextPage" object. I don't think this LoginDemo.java code has to do anything with the error but I prefer to post the entire code. Thanks in advance..

    //LoginDemo.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Login extends JFrame implements ActionListener
{
     JButton SUBMIT;
     JPanel panel;
     JLabel label1,label2;
     final JTextField  text1,text2;
    Login()
    {
        label1 = new JLabel();
        label1.setText("Username:");
        label1.setBounds(50,50,100,30);
        text1 = new JTextField(15);
        text1.setBounds(250,50,100,30);
        label2 = new JLabel();
        label2.setText("Password:");
        label2.setBounds(50,250,100,30);
        text2 = new JPasswordField(15);
        text2.setBounds(250,250,100,30);
        //this.setLayout(new BorderLayout());

        SUBMIT=new JButton("SUBMIT");
        SUBMIT.setBounds(350,350,100,30);

         //     panel=new JPanel(new GridLayout(3,1));
            panel=new JPanel(null);
        panel.setBounds(50,50,1000,1000);
        //  panel.setLayout(new FlowLayout());
        panel.add(label1);
        panel.add(text1);
        panel.add(label2);
        panel.add(text2);
        panel.add(SUBMIT);
            add(panel,BorderLayout.CENTER);
                SUBMIT.addActionListener(this);
                setTitle("LOGIN FORM");
    }
    public void actionPerformed(ActionEvent ae)
    {
        String value1=text1.getText();
        String value2=text2.getText();
        if (value1.equals("a") && value2.equals("a")) 
        {
            NextPage page=new NextPage();
            page.setVisible(true);
            //JLabel label = new JLabel("Welcome:"+value1);
                // page.getContentPane().add(label);
            setVisible(false);
        }
        else
        {
            //System.out.println("enter the valid username and password");
            JOptionPane.showMessageDialog(this,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
        }
    }
}   
class LoginDemo
{
    public static void main(String arg[])
{
    try
    {
        Login frame=new Login();
        frame.setSize(1000,1000);
        frame.setVisible(true);
    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, e.getMessage());
    }

    }
}



    //NextPage.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.Random; 
import java.sql.*;
import java.lang.*;
import java.awt.image.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class NextPage extends JFrame implements Runnable, ActionListener
{
        BufferedImage  img1,i0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,star1;
    JFrame f1;
    Thread t1,t2,t3;
    int x1,y1,i,j,k,l,m,n,r1,r2,r3;
    JButton b1;
    Random r=new Random();
    TextField tf1;
        JPanel p1;

    NextPage()
    {
        setBounds(50,50,1000,1000);
        p1=(JPanel)(getContentPane());
        p1.setBounds(50,50,1000, 1000);
        p1.setLayout(null);
        //tf1=new TextField(20);
        //tf1.setBounds(50,50,100,30);
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Welcome");

        b1=new JButton("START");

        //p1.add(tf1);  

        b1.setBounds(150,400,100,30);
        //try{
        b1.addActionListener(this);
        //}
        /*catch(Exception e)
        {
            System.out.println(""+e);
        }*/
        add(b1);
        setVisible(true);
        try
        {       
            i0=ImageIO.read(new File("tea.jpg"));   
                 i1=ImageIO.read(new File("coffee.jpg"));
             i2=ImageIO.read(new File("bhel.jpg")); 
            i3=ImageIO.read(new File("pizza.jpg")); 
             i4=ImageIO.read(new File("icecream.jpg")); 
             i5=ImageIO.read(new File("dosa.jpg")); 
             i6=ImageIO.read(new File("idli.jpg")); 
             i7=ImageIO.read(new File("panipuri.jpg")); 
             i8=ImageIO.read(new File("orange.jpg"));   
             i9=ImageIO.read(new File("watermelon.jpg"));   
             i10=ImageIO.read(new File("pavbhaji.jpg"));    
             i11=ImageIO.read(new File("noodles.jpg")); 
             i12=ImageIO.read(new File("sandwich.jpg"));    
         }
        catch (IOException ie) 
        {
            System.out.println("Error:"+ie.getMessage());   
        }

        j=0; m=0; n=0;

        r1= r.nextInt(13);
        r2= r.nextInt(13);
        r3= r.nextInt(13);

    }
    public void init()
    {
        t1=new Thread(this);
        t2=new Thread(this);
        t3=new Thread(this);
    }   

    public void start()
    {
        t2.start();
        t3.start();
    }
    public void run()
    {
        try
        {
            if(Thread.currentThread()==t1)
            for(j=0; j<150; j++)
            //for(i=0; i<=150; i+=20)
            {   
                r1= r.nextInt(13);
                repaint();  
                t1.sleep(10);
            }

            if(Thread.currentThread()==t2)
            for(m=0; m<160; m++)
            //for(k=0; k<=150; k+=20)
            {   
                r2= r.nextInt(13);
                repaint();
                t2.sleep(10);
            }
            if(Thread.currentThread()==t3)
            for(n=0; n<170; n++)
            //for(l=0; l<=150; l+=20)
            {   
                r3= r.nextInt(13);
                repaint();
                t3.sleep(10);
            }
        }
        catch(Exception e)
        {
            System.out.println(""+e);
        }

    }

    public void paint(Graphics g)
    {
        g.setColor(Color.blue);

        g.drawRect(50,300,150,80);
        g.drawRect(200,300,150,80);
        g.drawRect(350,300,150,80);

            switch(r1)
            {
                case 0: g.drawImage(i0,65,300,this);
                break;
                case 1: g.drawImage(i1,65,300,this);
                break;
                case 2: g.drawImage(i2,65,300,this);
                break;
                case 3: g.drawImage(i3,65,300,this);
                break;
                case 4: g.drawImage(i4,65,300,this);
                break;
                case 5: g.drawImage(i5,65,300,this);
                break;
                case 6: g.drawImage(i6,65,300,this);
                break;
                case 7: g.drawImage(i7,65,300,this);
                break;
                case 8: g.drawImage(i8,65,300,this);
                break;
                case 9: g.drawImage(i9,65,300,this);
                break;
                case 10: g.drawImage(i10,65,300,this);
                break;
                case 11: g.drawImage(i11,65,300,this);
                break;
                case 12: g.drawImage(i12,65,300,this);
                break;
            }   

            switch(r2)
            {
                case 0: g.drawImage(i0,215,300,this);
                break;
                case 1: g.drawImage(i1,215,300,this);
                break;
                case 2: g.drawImage(i2,215,300,this);
                break;
                case 3: g.drawImage(i3,215,300,this);
                break;
                case 4: g.drawImage(i4,215,300,this);
                break;
                case 5: g.drawImage(i5,215,300,this);
                break;
                case 6: g.drawImage(i6,215,300,this);
                break;
                case 7: g.drawImage(i7,215,300,this);
                break;
                case 8: g.drawImage(i8,215,300,this);
                break;
                case 9: g.drawImage(i9,215,300,this);
                break;
                case 10: g.drawImage(i10,215,300,this);
                break;
                case 11: g.drawImage(i11,215,300,this);
                break;
                case 12: g.drawImage(i12,215,300,this);
                break;
            }

            switch(r3)
            {
                case 0: g.drawImage(i0,365,300,this);
                break;
                case 1: g.drawImage(i1,365,300,this);
                break;
                case 2: g.drawImage(i2,365,300,this);
                break;
                case 3: g.drawImage(i3,365,300,this);
                break;
                case 4: g.drawImage(i4,365,300,this);
                break;
                case 5: g.drawImage(i5,365,300,this);
                break;
                case 6: g.drawImage(i6,365,300,this);
                break;
                case 7: g.drawImage(i7,365,300,this);
                break;
                case 8: g.drawImage(i8,365,300,this);
                break;
                case 9: g.drawImage(i9,365,300,this);
                break;
                case 10: g.drawImage(i10,365,300,this);
                break;
                case 11: g.drawImage(i11,365,300,this);
                break;
                case 12: g.drawImage(i12,365,300,this);
                break;
            }
        }
        public void actionPerformed(ActionEvent ae)
        {
            if(ae.getSource()==b1)
            t1.start();
        }

        /*public static void main(String args[])
        {
            NextPage o=new NextPage();
        }*/
    }   
} 

Here are the exceptions that I get-

F:\java\jdk\bin>java LoginDemo
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at NextPage.actionPerformed(NextPage.java:235)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
atjavax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6289)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6054)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4652)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4482)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4482)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
at java.awt.EventQueue.access$000(EventQueue.java:85)

at java.awt.EventQueue$1.run(EventQueue.java:603)

at java.awt.EventQueue$1.run(EventQueue.java:601)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87

at

java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98

at java.awt.EventQueue$2.run(EventQueue.java:617)

at java.awt.EventQueue$2.run(EventQueue.java:615)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87

at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)

at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Can't get any solution.. I am a learner..please help..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:17:49+00:00Added an answer on June 1, 2026 at 8:17 pm

    You used the variable t1 to start the thread that should be assigned to this variable. How ever the function init() that creates the instance of the thread that is assigned to this variable is never called. There for t1 is null and calling any function on a null object causes the NullPointerException.

    Simply call the init() function. I think the original idea was to call it within the constructor and you simply forgot to insert it.

    For future question please consider only posting the lines close to the point where the StackTrace reports the error. To find that spots of interest look into the StackTrace and look for entries in classes you wrote. In this case NextPage.actionPerformed(NextPage.java:235) is a point of interest. In your question best mark those spots to get a good resolution quickly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this login form which uses AJAX to query a database for checking
I have this login form on my program in C#, I will be matching
I have this button which submits the login form: <input class=btn btn-large btn-success id=login-button
I've been making this login form in C# and I wanted to 'submit' all
I have this login form. This form is a grouped table view where the
I have a login form for my website. This login form have two text
I am using this tutorial to create a login form http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/ It authenticates against
I got this from for a login form tutorial: function sanitize($securitystring) { $securitystring =
I've been reading this post Creating a login form in CodeIgniter based on Ion
I have this situation: There are a login page with a login form (form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.