• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lost in simple applets

 
Shilong Zheng
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am learning to program a simple applet here, I need to capture two inputs from user using a question dialog box and add them together and display the results. I am puzzled about how to convert the string to integer and display the results in the applet, kindly advise, below is the codes skeleton.


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

public class Applet1 extends JApplet {
boolean isStandalone = false;
/**Get a parameter value*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}

/**Construct the applet*/
public Applet1() {
}
/**Initialize the applet*/
public void init() {
try {
jbInit();
String input1 = JOptionPane.showInputDialog(null, "Enter 1st input", "Input Dialog",
JOptionPane.QUESTION_MESSAGE);
String input2 = JOptionPane.showInputDialog(null, "Enter 2nd input", "Input Dialog",
JOptionPane.QUESTION_MESSAGE);
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
this.setSize(new Dimension(400,300));
}
/**Get Applet information*/
public String getAppletInfo() {
return "Applet Information";
}
/**Get parameter info*/
public String[][] getParameterInfo() {
return null;
}

//static initializer for setting look & feel
static {
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exception e) {
}
}
}

Regards
Shilong
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic