The Artima Developer Community
Sponsored Link

Java Answers Forum
Java applet status bar issue !!!

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
laki

Posts: 1
Nickname: javan
Registered: Aug, 2002

Java applet status bar issue !!! Posted: Aug 19, 2002 3:26 PM
Reply to this message Reply
Advertisement
How can I overwrite 'Applet started.' in java applet before I do anything else. What I'm trying to do is when I run an applet I want to show a question in the status bar and then try to answer it to JTextField but I don't know how to do that. Below is the code:

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

public class Multiplication extends JApplet implements ActionListener {
JLabel showAnswer;
JTextField answer;
int usersAnswer, product, value1, value2;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());

showAnswer=new JLabel("Type in the answer: ");
answer=new JTextField(10);
answer.addActionListener(this);
c.add(showAnswer);
c.add(answer);
showStatus("");
}

public void start()
{
showStatusBar();
}

public void actionPerformed(ActionEvent e)
{
multiplication();
}

public void multiplication()
{
usersAnswer=Integer.parseInt(answer.getText());

if (usersAnswer==product) {
showStatus("Very good!");
}
if (usersAnswer!=product) {
showStatus("No.Please try again.");
}
}

public void showStatusBar()
{
value1=0+(int) (Math.random()*9);
value2=0+(int) (Math.random()*9);
showStatus("How much is "+value1+" times "+value2+"?");
product=value1*value2;
}
}

Topic: what are the non pure java components in swing...... Previous Topic   Next Topic Topic: Help with GUI

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use