Jump to content

Recommended Posts

Posted

ok so at my school we use this website for practice quizes but half the time its down and half the time there a bug or something that crashed and you have to restart. so im trying to write a group of programs that we be the quizes but i have run into a few problems the first is the Jlabel dose not update and secound is when you click the button it dose not put the data entered into the textfield into the string.

Heres the code

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

 

public class GUI extends Frame implements ActionListener

{

    int i=0;

    JLabel l1 = new JLabel();

    JTextField tf1 = new JTextField(2);

    JButton b1;

    String temp;

    public GUI()

    {

        GUI_1();

    }

 

    public void GUI_1()

    {

        int i=0;

        String temp;

        Game game = new Game(26);

        JFrame jf=new JFrame();

        jf.setTitle("testGUI");

        jf.setSize(500,300);

        JLabel l1=new JLabel("Enter the "+game.getE(i)+"?");

        JTextField tf1=new JTextField();

        JButton b1=new JButton("Submit");

        b1.addActionListener(this);

        temp=tf1.getText();

        Container pane=jf.getContentPane();

        pane.setLayout(new GridLayout(3,1) );

        pane.add(l1);

        pane.add(tf1);

        pane.add(b1);

        temp=tf1.getText();

        jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);

        jf.setVisible(true);

    }

 

    public void actionPerformed(ActionEvent e)

    {

        if(true==e.getActionCommand().equals("Submit"))

        {

            submit();

        }

    }

 

    public void submit()

    {

        JFrame jf=new JFrame();

        Game game = new Game(26);

        System.out.println("Passed button");

        l1.setText("Enter the"+game.getE(i+1)+"?");

        repaint();

        temp=tf1.getText();

        System.out.println("Temp = "+temp);

        if(temp!=null || temp != "" || temp != " ")

        {

            System.out.println("Passed if Else");

            game.play(temp,i);

            System.out.println("Passed Answer");

            if(game.getB()==false)

            {

                JOptionPane.showMessageDialog(jf,"You entered "+temp+" for "+game.getE(i)+" and the answer was "+game.getS(i),"Incorret",JOptionPane.ERROR_MESSAGE);

            }

            else

            {

                JOptionPane.showMessageDialog(jf,"Correct");

            }

            i++;

        }

        else

        {

            JOptionPane.showMessageDialog(jf,"You must answer","Invalid Answer",JOptionPane.ERROR_MESSAGE);

        }

    }

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...