| | |
how to run both as applet and or application
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
A JFrame can have a JApplet as content. Simply make the class a JApplet, and add the main function like what you see here:
Hope this helps!
Ed
Hope this helps!
Ed
Java Syntax (Toggle Plain Text)
// from http://www.devx.com/tips/Tip/16650 public class MyApplet extends JApplet { ... public static void main(String[] args) { Component applet = new MyApplet(); JFrame frame = new JFrame("My applet, as application"); frame.getContentPane().add(applet); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.show(); }
•
•
•
•
In a world without walls or fences,
What use are Windows and Gates.
•
•
Join Date: Dec 2004
Posts: 19
Reputation:
Solved Threads: 0
I found this did not work.
What did work was
- creating the applet as a JApplet not component
- calling init() explicitly
- using setVisible(true) & setSize(x,y)
What did work was
- creating the applet as a JApplet not component
- calling init() explicitly
- using setVisible(true) & setSize(x,y)
•
•
•
•
Originally Posted by cosi
A JFrame can have a JApplet as content. Simply make the class a JApplet, and add the main function like what you see here:
Hope this helps!
Ed
Java Syntax (Toggle Plain Text)
// from http://www.devx.com/tips/Tip/16650 public class MyApplet extends JApplet { ... public static void main(String[] args) { Component applet = new MyApplet(); JFrame frame = new JFrame("My applet, as application"); frame.getContentPane().add(applet); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.show(); }
•
•
Join Date: Sep 2007
Posts: 2
Reputation:
Solved Threads: 0
I face a tough problem to convert applet to application, can some one help me?
Here is my applet code:
import java.awt.*;
import java.util.*;
import java.applet.Applet;
import LogFontLayout;
import java.math.*;
class Dialog1 extends Dialog {
private static Applet applet;
Label pStatic1, pStatic2, pStatic3, pStatic4, pStatic5, pStatic6, pStatic7,
pStatic8, pStatic9, pStatic10, pStatic11;
Button pOK;
// Initial size in logical units
Dimension initialSize = new Dimension(299, 235);
Point initialLocation;
Dialog1(Applet app, Frame parent, String title, boolean modal) {
super(parent, title, modal);
applet = app;
setFont(new Font("Helvetica", Font.PLAIN, 12));
LogFontLayout lfLayout = new LogFontLayout(this);
setLayout(lfLayout);
pOK = new Button("OK");
add("128 200 35 17", pOK);
pStatic1 = new Label("Author, Comp");
add("7 5 250 15", pStatic1);
pStatic2 = new Label("$$$ donations or greeting cards are welcome.");
add("29 23 241 12", pStatic2);
pStatic3 = new Label("^ : exponential operator, e.g., 2 ^ 2.5 is 5.667, i.e., 2 to the power 2.5");
add("19 56 248 12", pStatic3);
pStatic4 = new Label("+ : addition, e.g., 2 + 7 is 9");
add("19 72 163 12", pStatic4);
pStatic5 = new Label("- : substration or negation, e.g., - - 5 - - - 3 is 2");
add("19 88 184 12", pStatic5);
pStatic6 = new Label("* : multiplication, e.g., 3 * 7 is 21");
add("19 104 179 12", pStatic6);
pStatic7 = new Label("/ : division, e.g., 7 / 2 is 3.5");
add("19 120 165 12", pStatic7);
pStatic8 = new Label("( : the left braket");
add("19 136 134 12", pStatic8);
pStatic9 = new Label(") : the right braket");
add("19 152 137 12", pStatic9);
pStatic10 = new Label("operator precedence order: ( ), - (negation), log, ^, * or /, + or - (substration)");
add("19 173 235 12", pStatic10);
pStatic11 = new Label("log: the natural logarithm of base e, e.g., log 2.718281829 = 1.00");
add("19 40 396 12", pStatic11);
// Size and Position in logical units
initialLocation = lfLayout.du(15, 28);
pack();
move(initialLocation.x, initialLocation.y);
}
public Dimension minimumSize() {
LayoutManager layoutMgr = getLayout();
if (layoutMgr instanceof LogFontLayout) {
// Convert from logical units to absolute coordinates
int w = initialSize.width;
int h = initialSize.height;
LogFontLayout layout = (LogFontLayout)layoutMgr;
return new Dimension(layout.duX(w), layout.duY(h));
}
return new Dimension(initialSize);
}
public boolean handleEvent(Event e) {
if (e.id == Event.WINDOW_DESTROY) {
dispose();
return true;
}
return super.handleEvent(e);
}
public boolean action(Event evt, Object obj) {
if (evt.target == pOK) {
dispose();
return true;
}
return true;
}
}
public
class simple2 extends Applet {
private static Applet applet;
TextField pEdit1;
Label pStatic01, pStatic02, pStatic03, pStatic04, pStatic05, pStatic06;
Button pButton1, pButton2, pButton3, pButton4, pButton5, pButton6, pButton7,
pButton8, pButton9, pButton10, pButton11, pButton12, pButton13, pButton14,
pButton15, pButton16, pButton17, pButton18, pButton19, pButton20, pButton21,
pButton22;
// Initial size in logical units
Dimension initialSize = new Dimension(291, 158);
String PreviousString = new String( " (-- 3 ) * 4" );
int read_at = 0;
int ActionTableSize = 545, GotoTableSize = 83, SymbolTableSize = 39;
String[] Symbol = {
"_$",
"_dot",
"_empty",
"_shift",
"_reduce",
"_accept",
"CAL",
"C",
"+",
"M",
"-",
"*",
"X",
"/",
"^",
"I",
"L",
"O",
"G",
"F",
"E",
"U",
"(",
")",
"P",
"N",
"Q",
".",
"D",
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
};
int[][] GotoTable = {
{34,25,10,-1},
{34,28,35,-1},
{32,26,11,-1},
{32,28,12,-1},
{30,7,13,-1},
{30,9,23,-1},
{30,12,25,-1},
{30,15,26,-1},
{30,19,28,-1},
{30,21,29,-1},
{30,24,31,-1},
{30,26,33,-1},
{30,25,32,-1},
{30,28,35,-1},
{24,21,17,-1},
{24,24,31,-1},
{24,26,33,-1},
{24,25,32,-1},
{24,28,35,-1},
{21,9,2,-1},
{21,12,25,-1},
{21,15,26,-1},
{21,19,28,-1},
{21,21,29,-1},
{21,24,31,-1},
{21,26,33,-1},
{21,25,32,-1},
{21,28,35,-1},
{20,9,3,-1},
{20,12,25,-1},
{20,15,26,-1},
{20,19,28,-1},
{20,21,29,-1},
{20,24,31,-1},
{20,26,33,-1},
{20,25,32,-1},
{20,28,35,-1},
{19,12,4,-1},
{19,15,26,-1},
{19,19,28,-1},
{19,21,29,-1},
{19,24,31,-1},
{19,26,33,-1},
{19,25,32,-1},
{19,28,35,-1},
{18,12,5,-1},
{18,15,26,-1},
{18,19,28,-1},
{18,21,29,-1},
{18,24,31,-1},
{18,26,33,-1},
{18,25,32,-1},
{18,28,35,-1},
{16,15,6,-1},
{16,19,28,-1},
{16,21,29,-1},
{16,24,31,-1},
{16,26,33,-1},
{16,25,32,-1},
{16,28,35,-1},
{14,21,8,-1},
{14,24,31,-1},
{14,26,33,-1},
{14,25,32,-1},
{14,28,35,-1},
{10,28,12,-1},
{7,15,1,-1},
{7,19,28,-1},
{7,21,29,-1},
{7,24,31,-1},
{7,26,33,-1},
{7,25,32,-1},
{7,28,35,-1},
{0,7,22,-1},
{0,9,23,-1},
{0,12,25,-1},
{0,15,26,-1},
{0,19,28,-1},
{0,21,29,-1},
{0,24,31,-1},
{0,26,33,-1},
{0,25,32,-1},
{0,28,35,-1}
};
int[][] ActionTable = {
{45,0,4,28,38,-1},
{45,23,4,28,38,-1},
{45,10,4,28,38,-1},
{45,8,4,28,38,-1},
{45,13,4,28,38,-1},
{45,11,4,28,38,-1},
{45,14,4,28,38,-1},
{45,20,4,28,38,-1},
{45,38,4,28,38,-1},
{45,37,4,28,38,-1},
{45,36,4,28,38,-1},
{45,35,4,28,38,-1},
{45,34,4,28,38,-1},
{45,33,4,28,38,-1},
{45,32,4,28,38,-1},
{45,31,4,28,38,-1},
{45,30,4,28,38,-1},
{45,29,4,28,38,-1},
{45,27,4,28,38,-1},
{44,0,4,28,37,-1},
{44,23,4,28,37,-1},
{44,10,4,28,37,-1},
{44,8,4,28,37,-1},
{44,13,4,28,37,-1},
{44,11,4,28,37,-1},
{44,14,4,28,37,-1},
{44,20,4,28,37,-1},
{44,38,4,28,37,-1},
{44,37,4,28,37,-1},
{44,36,4,28,37,-1},
{44,35,4,28,37,-1},
{44,34,4,28,37,-1},
{44,33,4,28,37,-1},
{44,32,4,28,37,-1},
{44,31,4,28,37,-1},
{44,30,4,28,37,-1},
{44,29,4,28,37,-1},
{44,27,4,28,37,-1},
{43,0,4,28,36,-1},
{43,23,4,28,36,-1},
{43,10,4,28,36,-1},
{43,8,4,28,36,-1},
{43,13,4,28,36,-1},
{43,11,4,28,36,-1},
{43,14,4,28,36,-1},
{43,20,4,28,36,-1},
{43,38,4,28,36,-1},
{43,37,4,28,36,-1},
{43,36,4,28,36,-1},
{43,35,4,28,36,-1},
{43,34,4,28,36,-1},
{43,33,4,28,36,-1},
{43,32,4,28,36,-1},
{43,31,4,28,36,-1},
{43,30,4,28,36,-1},
{43,29,4,28,36,-1},
{43,27,4,28,36,-1},
{42,0,4,28,35,-1},
{42,23,4,28,35,-1},
{42,10,4,28,35,-1},
{42,8,4,28,35,-1},
{42,13,4,28,35,-1},
{42,11,4,28,35,-1},
{42,14,4,28,35,-1},
{42,20,4,28,35,-1},
{42,38,4,28,35,-1},
{42,37,4,28,35,-1},
{42,36,4,28,35,-1},
{42,35,4,28,35,-1},
{42,34,4,28,35,-1},
{42,33,4,28,35,-1},
{42,32,4,28,35,-1},
{42,31,4,28,35,-1},
{42,30,4,28,35,-1},
{42,29,4,28,35,-1},
{42,27,4,28,35,-1},
{41,0,4,28,34,-1},
{41,23,4,28,34,-1},
{41,10,4,28,34,-1},
{41,8,4,28,34,-1},
{41,13,4,28,34,-1},
{41,11,4,28,34,-1},
{41,14,4,28,34,-1},
{41,20,4,28,34,-1},
{41,38,4,28,34,-1},
{41,37,4,28,34,-1},
{41,36,4,28,34,-1},
{41,35,4,28,34,-1},
{41,34,4,28,34,-1},
{41,33,4,28,34,-1},
{41,32,4,28,34,-1},
{41,31,4,28,34,-1},
{41,30,4,28,34,-1},
{41,29,4,28,34,-1},
{41,27,4,28,34,-1},
{40,0,4,28,33,-1},
{40,23,4,28,33,-1},
{40,10,4,28,33,-1},
{40,8,4,28,33,-1},
{40,13,4,28,33,-1},
{40,11,4,28,33,-1},
{40,14,4,28,33,-1},
{40,20,4,28,33,-1},
{40,38,4,28,33,-1},
{40,37,4,28,33,-1},
{40,36,4,28,33,-1},
{40,35,4,28,33,-1},
{40,34,4,28,33,-1},
{40,33,4,28,33,-1},
{40,32,4,28,33,-1},
{40,31,4,28,33,-1},
{40,30,4,28,33,-1},
{40,29,4,28,33,-1},
{40,27,4,28,33,-1},
{39,0,4,28,32,-1},
{39,23,4,28,32,-1},
{39,10,4,28,32,-1},
{39,8,4,28,32,-1},
{39,13,4,28,32,-1},
{39,11,4,28,32,-1},
{39,14,4,28,32,-1},
{39,20,4,28,32,-1},
{39,38,4,28,32,-1},
{39,37,4,28,32,-1},
{39,36,4,28,32,-1},
{39,35,4,28,32,-1},
{39,34,4,28,32,-1},
{39,33,4,28,32,-1},
{39,32,4,28,32,-1},
{39,31,4,28,32,-1},
{39,30,4,28,32,-1},
{39,29,4,28,32,-1},
{39,27,4,28,32,-1},
{38,0,4,28,31,-1},
{38,23,4,28,31,-1},
{38,10,4,28,31,-1},
{38,8,4,28,31,-1},
{38,13,4,28,31,-1},
{38,11,4,28,31,-1},
{38,14,4,28,31,-1},
{38,20,4,28,31,-1},
{38,38,4,28,31,-1},
{38,37,4,28,31,-1},
{38,36,4,28,31,-1},
{38,35,4,28,31,-1},
{38,34,4,28,31,-1},
{38,33,4,28,31,-1},
{38,32,4,28,31,-1},
{38,31,4,28,31,-1},
{38,30,4,28,31,-1},
{38,29,4,28,31,-1},
{38,27,4,28,31,-1},
{37,0,4,28,30,-1},
{37,23,4,28,30,-1},
{37,10,4,28,30,-1},
{37,8,4,28,30,-1},
{37,13,4,28,30,-1},
{37,11,4,28,30,-1},
{37,14,4,28,30,-1},
{37,20,4,28,30,-1},
{37,38,4,28,30,-1},
{37,37,4,28,30,-1},
{37,36,4,28,30,-1},
{37,35,4,28,30,-1},
{37,34,4,28,30,-1},
{37,33,4,28,30,-1},
{37,32,4,28,30,-1},
{37,31,4,28,30,-1},
{37,30,4,28,30,-1},
{37,29,4,28,30,-1},
{37,27,4,28,30,-1},
{36,0,4,28,29,-1},
{36,23,4,28,29,-1},
{36,10,4,28,29,-1},
{36,8,4,28,29,-1},
{36,13,4,28,29,-1},
{36,11,4,28,29,-1},
{36,14,4,28,29,-1},
{36,20,4,28,29,-1},
{36,38,4,28,29,-1},
{36,37,4,28,29,-1},
{36,36,4,28,29,-1},
{36,35,4,28,29,-1},
{36,34,4,28,29,-1},
{36,33,4,28,29,-1},
{36,32,4,28,29,-1},
{36,31,4,28,29,-1},
{36,30,4,28,29,-1},
{36,29,4,28,29,-1},
{36,27,4,28,29,-1},
{35,0,4,25,28,-1},
{35,23,4,25,28,-1},
{35,10,4,25,28,-1},
{35,8,4,25,28,-1},
{35,13,4,25,28,-1},
{35,11,4,25,28,-1},
{35,14,4,25,28,-1},
{35,20,4,25,28,-1},
{35,38,4,25,28,-1},
{35,37,4,25,28,-1},
{35,36,4,25,28,-1},
{35,35,4,25,28,-1},
{35,34,4,25,28,-1},
{35,33,4,25,28,-1},
{35,32,4,25,28,-1},
{35,31,4,25,28,-1},
{35,30,4,25,28,-1},
{35,29,4,25,28,-1},
{35,27,4,25,28,-1},
{34,29,3,36,-1},
{34,30,3,37,-1},
{34,31,3,38,-1},
{34,32,3,39,-1},
{34,33,3,40,-1},
{34,34,3,41,-1},
{34,35,3,42,-1},
{34,36,3,43,-1},
{34,37,3,44,-1},
{34,38,3,45,-1},
{33,0,4,21,26,-1},
{33,23,4,21,26,-1},
{33,10,4,21,26,-1},
{33,8,4,21,26,-1},
{33,13,4,21,26,-1},
{33,11,4,21,26,-1},
{33,14,4,21,26,-1},
{33,20,4,21,26,-1},
{32,0,4,21,25,-1},
{32,23,4,21,25,-1},
{32,10,4,21,25,-1},
{32,8,4,21,25,-1},
{32,13,4,21,25,-1},
{32,11,4,21,25,-1},
{32,14,4,21,25,-1},
{32,20,4,21,25,-1},
{32,29,3,36,-1},
{32,30,3,37,-1},
{32,31,3,38,-1},
{32,32,3,39,-1},
{32,33,3,40,-1},
{32,34,3,41,-1},
{32,35,3,42,-1},
{32,36,3,43,-1},
{32,37,3,44,-1},
{32,38,3,45,-1},
{32,27,3,34,-1},
{31,0,4,21,24,-1},
{31,23,4,21,24,-1},
{31,10,4,21,24,-1},
{31,8,4,21,24,-1},
{31,13,4,21,24,-1},
{31,11,4,21,24,-1},
{31,14,4,21,24,-1},
{31,20,4,21,24,-1},
{30,16,3,27,-1},
{30,10,3,24,-1},
{30,22,3,30,-1},
{30,27,3,34,-1},
{30,29,3,36,-1},
{30,30,3,37,-1},
{30,31,3,38,-1},
{30,32,3,39,-1},
{30,33,3,40,-1},
{30,34,3,41,-1},
{30,35,3,42,-1},
{30,36,3,43,-1},
{30,37,3,44,-1},
{30,38,3,45,-1},
{29,0,4,19,21,-1},
{29,23,4,19,21,-1},
{29,10,4,19,21,-1},
{29,8,4,19,21,-1},
{29,13,4,19,21,-1},
{29,11,4,19,21,-1},
{29,14,4,19,21,-1},
{29,20,4,19,21,-1},
{28,20,3,14,-1},
{28,0,4,15,19,-1},
{28,23,4,15,19,-1},
{28,10,4,15,19,-1},
{28,8,4,15,19,-1},
{28,13,4,15,19,-1},
{28,11,4,15,19,-1},
{28,14,4,15,19,-1},
{27,17,3,15,-1},
{26,0,4,12,15,-1},
{26,23,4,12,15,-1},
{26,10,4,12,15,-1},
{26,8,4,12,15,-1},
{26,13,4,12,15,-1},
{26,11,4,12,15,-1},
{26,14,4,12,15,-1},
{25,14,3,16,-1},
{25,0,4,9,12,-1},
{25,23,4,9,12,-1},
{25,10,4,9,12,-1},
{25,8,4,9,12,-1},
{25,13,4,9,12,-1},
{25,11,4,9,12,-1},
{24,10,3,24,-1},
{24,22,3,30,-1},
{24,27,3,34,-1},
{24,29,3,36,-1},
{24,30,3,37,-1},
{24,31,3,38,-1},
{24,32,3,39,-1},
{24,33,3,40,-1},
{24,34,3,41,-1},
{24,35,3,42,-1},
{24,36,3,43,-1},
{24,37,3,44,-1},
{24,38,3,45,-1},
{23,13,3,19,-1},
{23,11,3,18,-1},
{23,0,4,7,9,-1},
{23,23,4,7,9,-1},
{23,10,4,7,9,-1},
{23,8,4,7,9,-1},
{22,10,3,21,-1},
{22,8,3,20,-1},
{22,0,5,-1},
{21,16,3,27,-1},
{21,10,3,24,-1},
{21,22,3,30,-1},
{21,27,3,34,-1},
{21,29,3,36,-1},
{21,30,3,37,-1},
{21,31,3,38,-1},
{21,32,3,39,-1},
{21,33,3,40,-1},
{21,34,3,41,-1},
{21,35,3,42,-1},
{21,36,3,43,-1},
{21,37,3,44,-1},
{21,38,3,45,-1},
{20,16,3,27,-1},
{20,10,3,24,-1},
{20,22,3,30,-1},
{20,27,3,34,-1},
{20,29,3,36,-1},
{20,30,3,37,-1},
{20,31,3,38,-1},
{20,32,3,39,-1},
{20,33,3,40,-1},
{20,34,3,41,-1},
{20,35,3,42,-1},
{20,36,3,43,-1},
{20,37,3,44,-1},
{20,38,3,45,-1},
{19,16,3,27,-1},
{19,10,3,24,-1},
{19,22,3,30,-1},
{19,27,3,34,-1},
{19,29,3,36,-1},
{19,30,3,37,-1},
{19,31,3,38,-1},
{19,32,3,39,-1},
{19,33,3,40,-1},
{19,34,3,41,-1},
{19,35,3,42,-1},
{19,36,3,43,-1},
{19,37,3,44,-1},
{19,38,3,45,-1},
{18,16,3,27,-1},
{18,10,3,24,-1},
{18,22,3,30,-1},
{18,27,3,34,-1},
{18,29,3,36,-1},
{18,30,3,37,-1},
{18,31,3,38,-1},
{18,32,3,39,-1},
{18,33,3,40,-1},
{18,34,3,41,-1},
{18,35,3,42,-1},
{18,36,3,43,-1},
{18,37,3,44,-1},
{18,38,3,45,-1},
{17,0,4,21,10,21,-1},
{17,23,4,21,10,21,-1},
{17,10,4,21,10,21,-1},
{17,8,4,21,10,21,-1},
{17,13,4,21,10,21,-1},
{17,11,4,21,10,21,-1},
{17,14,4,21,10,21,-1},
{17,20,4,21,10,21,-1},
{16,16,3,27,-1},
{16,10,3,24,-1},
{16,22,3,30,-1},
{16,27,3,34,-1},
{16,29,3,36,-1},
{16,30,3,37,-1},
{16,31,3,38,-1},
{16,32,3,39,-1},
{16,33,3,40,-1},
{16,34,3,41,-1},
{16,35,3,42,-1},
{16,36,3,43,-1},
{16,37,3,44,-1},
{16,38,3,45,-1},
{15,18,3,7,-1},
{14,10,3,24,-1},
{14,22,3,30,-1},
{14,27,3,34,-1},
{14,29,3,36,-1},
{14,30,3,37,-1},
{14,31,3,38,-1},
{14,32,3,39,-1},
{14,33,3,40,-1},
{14,34,3,41,-1},
{14,35,3,42,-1},
{14,36,3,43,-1},
{14,37,3,44,-1},
{14,38,3,45,-1},
{13,10,3,21,-1},
{13,8,3,20,-1},
{13,23,3,9,-1},
{12,0,4,25,25,28,-1},
{12,23,4,25,25,28,-1},
{12,10,4,25,25,28,-1},
{12,8,4,25,25,28,-1},
{12,13,4,25,25,28,-1},
{12,11,4,25,25,28,-1},
{12,14,4,25,25,28,-1},
{12,20,4,25,25,28,-1},
{12,38,4,25,25,28,-1},
{12,37,4,25,25,28,-1},
{12,36,4,25,25,28,-1},
{12,35,4,25,25,28,-1},
{12,34,4,25,25,28,-1},
{12,33,4,25,25,28,-1},
{12,32,4,25,25,28,-1},
{12,31,4,25,25,28,-1},
{12,30,4,25,25,28,-1},
{12,29,4,25,25,28,-1},
{12,27,4,25,25,28,-1},
{11,0,4,24,25,26,-1},
{11,23,4,24,25,26,-1},
{11,10,4,24,25,26,-1},
{11,8,4,24,25,26,-1},
{11,13,4,24,25,26,-1},
{11,11,4,24,25,26,-1},
{11,14,4,24,25,26,-1},
{11,20,4,24,25,26,-1},
{10,0,4,26,27,25,-1},
{10,23,4,26,27,25,-1},
{10,10,4,26,27,25,-1},
{10,8,4,26,27,25,-1},
{10,13,4,26,27,25,-1},
{10,11,4,26,27,25,-1},
{10,14,4,26,27,25,-1},
{10,20,4,26,27,25,-1},
{10,29,3,36,-1},
{10,30,3,37,-1},
{10,31,3,38,-1},
{10,32,3,39,-1},
{10,33,3,40,-1},
{10,34,3,41,-1},
{10,35,3,42,-1},
{10,36,3,43,-1},
{10,37,3,44,-1},
{10,38,3,45,-1},
{9,0,4,21,22,7,23,-1},
{9,23,4,21,22,7,23,-1},
{9,10,4,21,22,7,23,-1},
{9,8,4,21,22,7,23,-1},
{9,13,4,21,22,7,23,-1},
{9,11,4,21,22,7,23,-1},
{9,14,4,21,22,7,23,-1},
{9,20,4,21,22,7,23,-1},
{8,0,4,19,19,20,21,-1},
{8,23,4,19,19,20,21,-1},
{8,10,4,19,19,20,21,-1},
{8,8,4,19,19,20,21,-1},
{8,13,4,19,19,20,21,-1},
{8,11,4,19,19,20,21,-1},
{8,14,4,19,19,20,21,-1},
{8,20,4,19,19,20,21,-1},
{7,16,3,27,-1},
{7,10,3,24,-1},
{7,22,3,30,-1},
{7,27,3,34,-1},
{7,29,3,36,-1},
{7,30,3,37,-1},
{7,31,3,38,-1},
{7,32,3,39,-1},
{7,33,3,40,-1},
{7,34,3,41,-1},
{7,35,3,42,-1},
{7,36,3,43,-1},
{7,37,3,44,-1},
{7,38,3,45,-1},
{6,0,4,12,12,14,15,-1},
{6,23,4,12,12,14,15,-1},
{6,10,4,12,12,14,15,-1},
{6,8,4,12,12,14,15,-1},
{6,13,4,12,12,14,15,-1},
{6,11,4,12,12,14,15,-1},
{6,14,4,12,12,14,15,-1},
{5,14,3,16,-1},
{5,0,4,9,9,11,12,-1},
{5,23,4,9,9,11,12,-1},
{5,10,4,9,9,11,12,-1},
{5,8,4,9,9,11,12,-1},
{5,13,4,9,9,11,12,-1},
{5,11,4,9,9,11,12,-1},
{4,14,3,16,-1},
{4,0,4,9,9,13,12,-1},
{4,23,4,9,9,13,12,-1},
{4,10,4,9,9,13,12,-1},
{4,8,4,9,9,13,12,-1},
{4,13,4,9,9,13,12,-1},
{4,11,4,9,9,13,12,-1},
{3,13,3,19,-1},
{3,11,3,18,-1},
{3,0,4,7,7,8,9,-1},
{3,23,4,7,7,8,9,-1},
{3,10,4,7,7,8,9,-1},
{3,8,4,7,7,8,9,-1},
{2,13,3,19,-1},
{2,11,3,18,-1},
{2,0,4,7,7,10,9,-1},
{2,23,4,7,7,10,9,-1},
{2,10,4,7,7,10,9,-1},
{2,8,4,7,7,10,9,-1},
{1,0,4,15,16,17,18,15,-1},
{1,23,4,15,16,17,18,15,-1},
{1,10,4,15,16,17,18,15,-1},
{1,8,4,15,16,17,18,15,-1},
{1,13,4,15,16,17,18,15,-1},
{1,11,4,15,16,17,18,15,-1},
{1,14,4,15,16,17,18,15,-1},
{0,16,3,27,-1},
{0,10,3,24,-1},
{0,22,3,30,-1},
{0,27,3,34,-1},
{0,29,3,36,-1},
{0,30,3,37,-1},
{0,31,3,38,-1},
{0,32,3,39,-1},
{0,33,3,40,-1},
{0,34,3,41,-1},
{0,35,3,42,-1},
{0,36,3,43,-1},
{0,37,3,44,-1},
{0,38,3,45,-1}
};
public
void init() {
applet = this;
setBackground(Color.lightGray);
setFont(new Font("Courier", Font.BOLD, 12));
LogFontLayout lfLayout = new LogFontLayout(this);
setLayout(lfLayout);
pButton1 = new Button("log");
add("17 35 32 12", pButton1);
pEdit1 = new TextField(" (-- 3 ) * 4");
add("17 17 201 14", pEdit1);
pButton2 = new Button("(");
add("54 35 32 12", pButton2);
pButton3 = new Button(")");
add("91 35 32 12", pButton3);
pButton4 = new Button("^");
add("130 35 32 12", pButton4);
pButton5 = new Button("7");
add("17 51 32 12", pButton5);
pButton6 = new Button("8");
add("55 51 32 12", pButton6);
pButton7 = new Button("9");
add("93 51 32 12", pButton7);
pButton8 = new Button("+");
add("131 51 32 12", pButton8);
pButton9 = new Button("4");
add("17 67 32 12", pButton9);
pButton10 = new Button("5");
add("55 67 32 12", pButton10);
pButton11 = new Button("6");
add("93 67 32 12", pButton11);
pButton12 = new Button("-");
add("131 67 32 12", pButton12);
pButton13 = new Button("1");
add("17 83 32 12", pButton13);
pButton14 = new Button("2");
add("55 83 32 12", pButton14);
pButton15 = new Button("3");
add("93 83 32 12", pButton15);
pButton16 = new Button("*");
add("131 83 32 12", pButton16);
pButton17 = new Button("0");
add("17 99 32 12", pButton17);
pButton18 = new Button(".");
add("55 99 32 12", pButton18);
pButton19 = new Button("Compute");
add("93 99 32 12", pButton19);
pButton20 = new Button("/");
add("131 99 32 12", pButton20);
pStatic01 = new Label("LR1 Calculator 1.0, by EllenT,all rights reserved");
add("5 3 269 12", pStatic01);
pButton21 = new Button("Help");
add("93 117 69 12", pButton21);
pStatic02 = new Label("substraction or negation");
add("167 66 100 14", pStatic02);
pStatic03 = new Label("addition");
add("166 51 85 12", pStatic03);
pStatic04 = new Label("exponential");
add("165 35 94 12", pStatic04);
pStatic05 = new Label("multiplication");
add("167 83 95 12", pStatic05);
pStatic06 = new Label("division");
add("168 99 94 12", pStatic06);
pButton22 = new Button("Replay");
add("17 117 70 12", pButton22);
// Size in logical units
resize(getLayout().preferredLayoutSize(this));
pEdit1.setCaretPosition( pEdit1.getText().length() );
pEdit1.requestFocus();
}
public Dimension minimumSize() {
LayoutManager layoutMgr = getLayout();
if (layoutMgr instanceof LogFontLayout) {
// Convert from logical units to absolute coordinates
int w = initialSize.width;
int h = initialSize.height;
LogFontLayout layout = (LogFontLayout)layoutMgr;
return new Dimension(layout.duX(w), layout.duY(h));
}
return new Dimension(initialSize);
}
public boolean handleEvent(Event e) {
if (e.target == pEdit1 && e.id == Event.GOT_FOCUS) {
return false;
}
return super.handleEvent(e);
}
public Frame getFrame(Container c) {
if (c instanceof Frame || c == null)
return((Frame)c);
else
return(getFrame(c.getParent()));
}
public boolean action(Event evt, Object obj) {
if (evt.target == pButton1) {
String tempS = pButton1.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton2) {
String tempS = pButton2.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton3) {
String tempS = pButton3.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton4) {
String tempS = pButton4.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton5) {
String tempS = pButton5.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton6) {
String tempS = pButton6.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton7) {
String tempS = pButton7.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton8) {
String tempS = pButton8.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton9) {
String tempS = pButton9.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton10) {
String tempS = pButton10.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton11) {
String tempS = pButton11.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton12) {
String tempS = pButton12.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton13) {
String tempS = pButton13.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton14) {
String tempS = pButton14.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton15) {
String tempS = pButton15.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton16) {
String tempS = pButton16.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton17) {
String tempS = pButton17.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton18) {
String tempS = pButton18.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if ((evt.target == pButton19) || (evt.target == pEdit1)) {
String InputString = pEdit1.getText();
int[] symbol_stack = new int[900];
double[] compute_stack = new double[200];
int[] N_length_stack = new int[200];
int symbol_stack_size = 0,
compute_stack_size = 0,
N_length_stack_size = 0,
done = 0, T, i, j, k, a, b, sleep_length = 1500;
Character c;
double f1, f2;
symbol_stack[0] = 0;
symbol_stack_size = 1;
compute_stack[0] = 0;
compute_stack_size = 1;
if (InputString.length() == 0)
InputString = new String("0");
// delete spaces.
read_at = 0;
while ((read_at < InputString.length()) && (InputString.charAt(read_at) == ' '))
read_at++;
// find the index of the read input.
a = 0;
if (read_at < InputString.length()) {
while ((a < SymbolTableSize) &&
(Symbol[a].compareTo( InputString.substring(read_at, read_at + 1).toUpperCase() ) != 0) )
a++;
if (a >= SymbolTableSize)
a = -1;
}
while (done != 1) {
// search the action table: action[symbol_stack[sym_bol_stack_size - 1], a]
i = 0;
while ((i < ActionTableSize) &&
((ActionTable[i][0] != symbol_stack[symbol_stack_size - 1]) ||
(ActionTable[i][1] != a))) {
i++;
}
if (i >= ActionTableSize) {
// error!!
PreviousString = new String( pEdit1.getText() );
pEdit1.setText( "Syntax Error!!!" );
try {
Thread.sleep(sleep_length);
}
catch (InterruptedException e) {
}
pEdit1.setText( PreviousString );
pEdit1.setCaretPosition(read_at);
pEdit1.select( read_at, read_at + 1);
done = 1;
}
else if (Symbol[ActionTable[i][2]].compareTo( "_shift" )== 0) {
symbol_stack[symbol_stack_size] = a;
symbol_stack_size++;
symbol_stack[symbol_stack_size] = ActionTable[i][3];
symbol_stack_size++;
// delete spaces
j = InputString.length();
read_at++;
while ((read_at < j) && (InputString.charAt(read_at) == ' '))
read_at++;
a = 0; // the "end" symbol
if (read_at < InputString.length()) {
while ((a < SymbolTableSize) &&
(Symbol[a].compareTo( InputString.substring(read_at, read_at + 1).toUpperCase() ) != 0))
a++;
if (a >= SymbolTableSize)
a = -1;
}
if (a == -1) {
PreviousString = new String( pEdit1.getText() );
pEdit1.setText( "Syntax Error!!!" );
try {
Thread.sleep(sleep_length);
}
catch (InterruptedException e) {
}
pEdit1.setText( PreviousString );
pEdit1.setCaretPosition(read_at);
pEdit1.select( read_at, read_at + 1 );
done = 1;
}
}
else if (Symbol[ActionTable[i][2]].compareTo( "_reduce" )== 0) {
b = 4;
while (ActionTable[i][b] >= 0)
b++;
symbol_stack_size -= (2 * (b - 4));
symbol_stack[symbol_stack_size] = ActionTable[i][3];
symbol_stack_size++;
j = 0;
while ((j < GotoTableSize) &&
((GotoTable[j][0] != symbol_stack[symbol_stack_size - 2]) ||
(GotoTable[j][1] != symbol_stack[symbol_stack_size - 1]))) {
j++;
}
symbol_stack[symbol_stack_size] = GotoTable[j][2];
symbol_stack_size++;
// all the reduction rules' translation
if (Symbol[ActionTable[i][3]].compareTo( "D" ) == 0) {
compute_stack[compute_stack_size] = 1.0 * Character.digit(Symbol[ActionTable[i][4]].charAt(0), 10);
compute_stack_size++;
N_length_stack[N_length_stack_size] = 1;
N_length_stack_size++;
}
else if (Symbol[ActionTable[i][3]].compareTo( "N" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "N" ) == 0) {
compute_stack_size--;
compute_stack[compute_stack_size - 1] =
10.0*compute_stack[compute_stack_size - 1] + compute_stack[compute_stack_size];
N_length_stack_size--;
N_length_stack[N_length_stack_size - 1] += N_length_stack[N_length_stack_size];
}
}
else if (Symbol[ActionTable[i][3]].compareTo( "Q" ) == 0) {
compute_stack[compute_stack_size - 1] /=
Math.pow( 10.0, 1.0 * N_length_stack[N_length_stack_size - 1] );
N_length_stack_size--;
}
else if (Symbol[ActionTable[i][3]].compareTo( "P" ) == 0) {
compute_stack_size--;
compute_stack[compute_stack_size - 1] += compute_stack[compute_stack_size];
N_length_stack_size--;
}
else if (Symbol[ActionTable[i][3]].compareTo( "U" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "N" ) == 0)
N_length_stack_size--;
else if (Symbol[ActionTable[i][4]].compareTo( "-" ) == 0)
compute_stack[compute_stack_size - 1] *= -1.0;
}
else if (Symbol[ActionTable[i][3]].compareTo( "F" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "F" ) == 0) {
compute_stack_size--;
compute_stack[compute_stack_size - 1] *= Math.pow(10.0, compute_stack[compute_stack_size]);
}
}
else if (Symbol[ActionTable[i][3]].compareTo( "X" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "X" ) == 0) {
compute_stack_size--;
compute_stack[compute_stack_size - 1] =
Math.pow( compute_stack[compute_stack_size - 1],
compute_stack[compute_stack_size]);
}
}
else if (Symbol[ActionTable[i][3]].compareTo( "I" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "L" ) == 0) {
if (compute_stack[compute_stack_size - 1] >= 0)
compute_stack[compute_stack_size - 1] = Math.log( compute_stack[compute_stack_size - 1] );
else {
PreviousString = new String( pEdit1.getText() );
pEdit1.setText( "Error: log(a negative number)!!!" );
try {
Thread.sleep(sleep_length);
}
catch (InterruptedException e) {
}
pEdit1.setText( PreviousString );
pEdit1.setCaretPosition(read_at);
pEdit1.select( read_at, read_at + 1 );
done = 1;
}
}
}
else if (Symbol[ActionTable[i][3]].compareTo( "M" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "M" ) == 0) {
if (Symbol[ActionTable[i][5]].compareTo( "/" ) == 0) {
if (compute_stack[compute_stack_size - 1] == 0) {
PreviousString = new String( pEdit1.getText() );
pEdit1.setText( "Error: divided by zero!!!" );
try {
Thread.sleep(sleep_length);
}
catch (InterruptedException e) {
}
pEdit1.setText( PreviousString );
pEdit1.setCaretPosition(read_at);
pEdit1.select( read_at, read_at + 1 );
done = 1;
}
else {
compute_stack_size--;
compute_stack[compute_stack_size - 1] /= compute_stack[compute_stack_size];
}
}
else {
compute_stack_size--;
compute_stack[compute_stack_size - 1] *= compute_stack[compute_stack_size];
}
}
}
else if (Symbol[ActionTable[i][3]].compareTo( "C" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "C" ) == 0) {
if (Symbol[ActionTable[i][5]].compareTo( "-" ) == 0) {
compute_stack_size--;
compute_stack[compute_stack_size - 1] -= compute_stack[compute_stack_size];
}
else {
compute_stack_size--;
compute_stack[compute_stack_size - 1] += compute_stack[compute_stack_size];
}
}
}
}
else if (Symbol[ActionTable[i][2]].compareTo( "_accept" )== 0) {
PreviousString = new String( pEdit1.getText() );
pEdit1.setText( Double.toString(compute_stack[compute_stack_size - 1]) );
pEdit1.setCaretPosition( pEdit1.getText().length() );
done = 1;
}
}
pEdit1.requestFocus();
}
else if (evt.target == pButton20) {
String tempS = pButton20.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton21) {
Dialog1 dDialog1= new Dialog1(applet, getFrame(this), "About", true);
dDialog1.show();
pEdit1.requestFocus();
}
else if (evt.target == pButton22) {
pEdit1.setText( PreviousString );
pEdit1.setCaretPosition( PreviousString.length() );
pEdit1.requestFocus();
}
return true;
}
}
Here is my applet code:
import java.awt.*;
import java.util.*;
import java.applet.Applet;
import LogFontLayout;
import java.math.*;
class Dialog1 extends Dialog {
private static Applet applet;
Label pStatic1, pStatic2, pStatic3, pStatic4, pStatic5, pStatic6, pStatic7,
pStatic8, pStatic9, pStatic10, pStatic11;
Button pOK;
// Initial size in logical units
Dimension initialSize = new Dimension(299, 235);
Point initialLocation;
Dialog1(Applet app, Frame parent, String title, boolean modal) {
super(parent, title, modal);
applet = app;
setFont(new Font("Helvetica", Font.PLAIN, 12));
LogFontLayout lfLayout = new LogFontLayout(this);
setLayout(lfLayout);
pOK = new Button("OK");
add("128 200 35 17", pOK);
pStatic1 = new Label("Author, Comp");
add("7 5 250 15", pStatic1);
pStatic2 = new Label("$$$ donations or greeting cards are welcome.");
add("29 23 241 12", pStatic2);
pStatic3 = new Label("^ : exponential operator, e.g., 2 ^ 2.5 is 5.667, i.e., 2 to the power 2.5");
add("19 56 248 12", pStatic3);
pStatic4 = new Label("+ : addition, e.g., 2 + 7 is 9");
add("19 72 163 12", pStatic4);
pStatic5 = new Label("- : substration or negation, e.g., - - 5 - - - 3 is 2");
add("19 88 184 12", pStatic5);
pStatic6 = new Label("* : multiplication, e.g., 3 * 7 is 21");
add("19 104 179 12", pStatic6);
pStatic7 = new Label("/ : division, e.g., 7 / 2 is 3.5");
add("19 120 165 12", pStatic7);
pStatic8 = new Label("( : the left braket");
add("19 136 134 12", pStatic8);
pStatic9 = new Label(") : the right braket");
add("19 152 137 12", pStatic9);
pStatic10 = new Label("operator precedence order: ( ), - (negation), log, ^, * or /, + or - (substration)");
add("19 173 235 12", pStatic10);
pStatic11 = new Label("log: the natural logarithm of base e, e.g., log 2.718281829 = 1.00");
add("19 40 396 12", pStatic11);
// Size and Position in logical units
initialLocation = lfLayout.du(15, 28);
pack();
move(initialLocation.x, initialLocation.y);
}
public Dimension minimumSize() {
LayoutManager layoutMgr = getLayout();
if (layoutMgr instanceof LogFontLayout) {
// Convert from logical units to absolute coordinates
int w = initialSize.width;
int h = initialSize.height;
LogFontLayout layout = (LogFontLayout)layoutMgr;
return new Dimension(layout.duX(w), layout.duY(h));
}
return new Dimension(initialSize);
}
public boolean handleEvent(Event e) {
if (e.id == Event.WINDOW_DESTROY) {
dispose();
return true;
}
return super.handleEvent(e);
}
public boolean action(Event evt, Object obj) {
if (evt.target == pOK) {
dispose();
return true;
}
return true;
}
}
public
class simple2 extends Applet {
private static Applet applet;
TextField pEdit1;
Label pStatic01, pStatic02, pStatic03, pStatic04, pStatic05, pStatic06;
Button pButton1, pButton2, pButton3, pButton4, pButton5, pButton6, pButton7,
pButton8, pButton9, pButton10, pButton11, pButton12, pButton13, pButton14,
pButton15, pButton16, pButton17, pButton18, pButton19, pButton20, pButton21,
pButton22;
// Initial size in logical units
Dimension initialSize = new Dimension(291, 158);
String PreviousString = new String( " (-- 3 ) * 4" );
int read_at = 0;
int ActionTableSize = 545, GotoTableSize = 83, SymbolTableSize = 39;
String[] Symbol = {
"_$",
"_dot",
"_empty",
"_shift",
"_reduce",
"_accept",
"CAL",
"C",
"+",
"M",
"-",
"*",
"X",
"/",
"^",
"I",
"L",
"O",
"G",
"F",
"E",
"U",
"(",
")",
"P",
"N",
"Q",
".",
"D",
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
};
int[][] GotoTable = {
{34,25,10,-1},
{34,28,35,-1},
{32,26,11,-1},
{32,28,12,-1},
{30,7,13,-1},
{30,9,23,-1},
{30,12,25,-1},
{30,15,26,-1},
{30,19,28,-1},
{30,21,29,-1},
{30,24,31,-1},
{30,26,33,-1},
{30,25,32,-1},
{30,28,35,-1},
{24,21,17,-1},
{24,24,31,-1},
{24,26,33,-1},
{24,25,32,-1},
{24,28,35,-1},
{21,9,2,-1},
{21,12,25,-1},
{21,15,26,-1},
{21,19,28,-1},
{21,21,29,-1},
{21,24,31,-1},
{21,26,33,-1},
{21,25,32,-1},
{21,28,35,-1},
{20,9,3,-1},
{20,12,25,-1},
{20,15,26,-1},
{20,19,28,-1},
{20,21,29,-1},
{20,24,31,-1},
{20,26,33,-1},
{20,25,32,-1},
{20,28,35,-1},
{19,12,4,-1},
{19,15,26,-1},
{19,19,28,-1},
{19,21,29,-1},
{19,24,31,-1},
{19,26,33,-1},
{19,25,32,-1},
{19,28,35,-1},
{18,12,5,-1},
{18,15,26,-1},
{18,19,28,-1},
{18,21,29,-1},
{18,24,31,-1},
{18,26,33,-1},
{18,25,32,-1},
{18,28,35,-1},
{16,15,6,-1},
{16,19,28,-1},
{16,21,29,-1},
{16,24,31,-1},
{16,26,33,-1},
{16,25,32,-1},
{16,28,35,-1},
{14,21,8,-1},
{14,24,31,-1},
{14,26,33,-1},
{14,25,32,-1},
{14,28,35,-1},
{10,28,12,-1},
{7,15,1,-1},
{7,19,28,-1},
{7,21,29,-1},
{7,24,31,-1},
{7,26,33,-1},
{7,25,32,-1},
{7,28,35,-1},
{0,7,22,-1},
{0,9,23,-1},
{0,12,25,-1},
{0,15,26,-1},
{0,19,28,-1},
{0,21,29,-1},
{0,24,31,-1},
{0,26,33,-1},
{0,25,32,-1},
{0,28,35,-1}
};
int[][] ActionTable = {
{45,0,4,28,38,-1},
{45,23,4,28,38,-1},
{45,10,4,28,38,-1},
{45,8,4,28,38,-1},
{45,13,4,28,38,-1},
{45,11,4,28,38,-1},
{45,14,4,28,38,-1},
{45,20,4,28,38,-1},
{45,38,4,28,38,-1},
{45,37,4,28,38,-1},
{45,36,4,28,38,-1},
{45,35,4,28,38,-1},
{45,34,4,28,38,-1},
{45,33,4,28,38,-1},
{45,32,4,28,38,-1},
{45,31,4,28,38,-1},
{45,30,4,28,38,-1},
{45,29,4,28,38,-1},
{45,27,4,28,38,-1},
{44,0,4,28,37,-1},
{44,23,4,28,37,-1},
{44,10,4,28,37,-1},
{44,8,4,28,37,-1},
{44,13,4,28,37,-1},
{44,11,4,28,37,-1},
{44,14,4,28,37,-1},
{44,20,4,28,37,-1},
{44,38,4,28,37,-1},
{44,37,4,28,37,-1},
{44,36,4,28,37,-1},
{44,35,4,28,37,-1},
{44,34,4,28,37,-1},
{44,33,4,28,37,-1},
{44,32,4,28,37,-1},
{44,31,4,28,37,-1},
{44,30,4,28,37,-1},
{44,29,4,28,37,-1},
{44,27,4,28,37,-1},
{43,0,4,28,36,-1},
{43,23,4,28,36,-1},
{43,10,4,28,36,-1},
{43,8,4,28,36,-1},
{43,13,4,28,36,-1},
{43,11,4,28,36,-1},
{43,14,4,28,36,-1},
{43,20,4,28,36,-1},
{43,38,4,28,36,-1},
{43,37,4,28,36,-1},
{43,36,4,28,36,-1},
{43,35,4,28,36,-1},
{43,34,4,28,36,-1},
{43,33,4,28,36,-1},
{43,32,4,28,36,-1},
{43,31,4,28,36,-1},
{43,30,4,28,36,-1},
{43,29,4,28,36,-1},
{43,27,4,28,36,-1},
{42,0,4,28,35,-1},
{42,23,4,28,35,-1},
{42,10,4,28,35,-1},
{42,8,4,28,35,-1},
{42,13,4,28,35,-1},
{42,11,4,28,35,-1},
{42,14,4,28,35,-1},
{42,20,4,28,35,-1},
{42,38,4,28,35,-1},
{42,37,4,28,35,-1},
{42,36,4,28,35,-1},
{42,35,4,28,35,-1},
{42,34,4,28,35,-1},
{42,33,4,28,35,-1},
{42,32,4,28,35,-1},
{42,31,4,28,35,-1},
{42,30,4,28,35,-1},
{42,29,4,28,35,-1},
{42,27,4,28,35,-1},
{41,0,4,28,34,-1},
{41,23,4,28,34,-1},
{41,10,4,28,34,-1},
{41,8,4,28,34,-1},
{41,13,4,28,34,-1},
{41,11,4,28,34,-1},
{41,14,4,28,34,-1},
{41,20,4,28,34,-1},
{41,38,4,28,34,-1},
{41,37,4,28,34,-1},
{41,36,4,28,34,-1},
{41,35,4,28,34,-1},
{41,34,4,28,34,-1},
{41,33,4,28,34,-1},
{41,32,4,28,34,-1},
{41,31,4,28,34,-1},
{41,30,4,28,34,-1},
{41,29,4,28,34,-1},
{41,27,4,28,34,-1},
{40,0,4,28,33,-1},
{40,23,4,28,33,-1},
{40,10,4,28,33,-1},
{40,8,4,28,33,-1},
{40,13,4,28,33,-1},
{40,11,4,28,33,-1},
{40,14,4,28,33,-1},
{40,20,4,28,33,-1},
{40,38,4,28,33,-1},
{40,37,4,28,33,-1},
{40,36,4,28,33,-1},
{40,35,4,28,33,-1},
{40,34,4,28,33,-1},
{40,33,4,28,33,-1},
{40,32,4,28,33,-1},
{40,31,4,28,33,-1},
{40,30,4,28,33,-1},
{40,29,4,28,33,-1},
{40,27,4,28,33,-1},
{39,0,4,28,32,-1},
{39,23,4,28,32,-1},
{39,10,4,28,32,-1},
{39,8,4,28,32,-1},
{39,13,4,28,32,-1},
{39,11,4,28,32,-1},
{39,14,4,28,32,-1},
{39,20,4,28,32,-1},
{39,38,4,28,32,-1},
{39,37,4,28,32,-1},
{39,36,4,28,32,-1},
{39,35,4,28,32,-1},
{39,34,4,28,32,-1},
{39,33,4,28,32,-1},
{39,32,4,28,32,-1},
{39,31,4,28,32,-1},
{39,30,4,28,32,-1},
{39,29,4,28,32,-1},
{39,27,4,28,32,-1},
{38,0,4,28,31,-1},
{38,23,4,28,31,-1},
{38,10,4,28,31,-1},
{38,8,4,28,31,-1},
{38,13,4,28,31,-1},
{38,11,4,28,31,-1},
{38,14,4,28,31,-1},
{38,20,4,28,31,-1},
{38,38,4,28,31,-1},
{38,37,4,28,31,-1},
{38,36,4,28,31,-1},
{38,35,4,28,31,-1},
{38,34,4,28,31,-1},
{38,33,4,28,31,-1},
{38,32,4,28,31,-1},
{38,31,4,28,31,-1},
{38,30,4,28,31,-1},
{38,29,4,28,31,-1},
{38,27,4,28,31,-1},
{37,0,4,28,30,-1},
{37,23,4,28,30,-1},
{37,10,4,28,30,-1},
{37,8,4,28,30,-1},
{37,13,4,28,30,-1},
{37,11,4,28,30,-1},
{37,14,4,28,30,-1},
{37,20,4,28,30,-1},
{37,38,4,28,30,-1},
{37,37,4,28,30,-1},
{37,36,4,28,30,-1},
{37,35,4,28,30,-1},
{37,34,4,28,30,-1},
{37,33,4,28,30,-1},
{37,32,4,28,30,-1},
{37,31,4,28,30,-1},
{37,30,4,28,30,-1},
{37,29,4,28,30,-1},
{37,27,4,28,30,-1},
{36,0,4,28,29,-1},
{36,23,4,28,29,-1},
{36,10,4,28,29,-1},
{36,8,4,28,29,-1},
{36,13,4,28,29,-1},
{36,11,4,28,29,-1},
{36,14,4,28,29,-1},
{36,20,4,28,29,-1},
{36,38,4,28,29,-1},
{36,37,4,28,29,-1},
{36,36,4,28,29,-1},
{36,35,4,28,29,-1},
{36,34,4,28,29,-1},
{36,33,4,28,29,-1},
{36,32,4,28,29,-1},
{36,31,4,28,29,-1},
{36,30,4,28,29,-1},
{36,29,4,28,29,-1},
{36,27,4,28,29,-1},
{35,0,4,25,28,-1},
{35,23,4,25,28,-1},
{35,10,4,25,28,-1},
{35,8,4,25,28,-1},
{35,13,4,25,28,-1},
{35,11,4,25,28,-1},
{35,14,4,25,28,-1},
{35,20,4,25,28,-1},
{35,38,4,25,28,-1},
{35,37,4,25,28,-1},
{35,36,4,25,28,-1},
{35,35,4,25,28,-1},
{35,34,4,25,28,-1},
{35,33,4,25,28,-1},
{35,32,4,25,28,-1},
{35,31,4,25,28,-1},
{35,30,4,25,28,-1},
{35,29,4,25,28,-1},
{35,27,4,25,28,-1},
{34,29,3,36,-1},
{34,30,3,37,-1},
{34,31,3,38,-1},
{34,32,3,39,-1},
{34,33,3,40,-1},
{34,34,3,41,-1},
{34,35,3,42,-1},
{34,36,3,43,-1},
{34,37,3,44,-1},
{34,38,3,45,-1},
{33,0,4,21,26,-1},
{33,23,4,21,26,-1},
{33,10,4,21,26,-1},
{33,8,4,21,26,-1},
{33,13,4,21,26,-1},
{33,11,4,21,26,-1},
{33,14,4,21,26,-1},
{33,20,4,21,26,-1},
{32,0,4,21,25,-1},
{32,23,4,21,25,-1},
{32,10,4,21,25,-1},
{32,8,4,21,25,-1},
{32,13,4,21,25,-1},
{32,11,4,21,25,-1},
{32,14,4,21,25,-1},
{32,20,4,21,25,-1},
{32,29,3,36,-1},
{32,30,3,37,-1},
{32,31,3,38,-1},
{32,32,3,39,-1},
{32,33,3,40,-1},
{32,34,3,41,-1},
{32,35,3,42,-1},
{32,36,3,43,-1},
{32,37,3,44,-1},
{32,38,3,45,-1},
{32,27,3,34,-1},
{31,0,4,21,24,-1},
{31,23,4,21,24,-1},
{31,10,4,21,24,-1},
{31,8,4,21,24,-1},
{31,13,4,21,24,-1},
{31,11,4,21,24,-1},
{31,14,4,21,24,-1},
{31,20,4,21,24,-1},
{30,16,3,27,-1},
{30,10,3,24,-1},
{30,22,3,30,-1},
{30,27,3,34,-1},
{30,29,3,36,-1},
{30,30,3,37,-1},
{30,31,3,38,-1},
{30,32,3,39,-1},
{30,33,3,40,-1},
{30,34,3,41,-1},
{30,35,3,42,-1},
{30,36,3,43,-1},
{30,37,3,44,-1},
{30,38,3,45,-1},
{29,0,4,19,21,-1},
{29,23,4,19,21,-1},
{29,10,4,19,21,-1},
{29,8,4,19,21,-1},
{29,13,4,19,21,-1},
{29,11,4,19,21,-1},
{29,14,4,19,21,-1},
{29,20,4,19,21,-1},
{28,20,3,14,-1},
{28,0,4,15,19,-1},
{28,23,4,15,19,-1},
{28,10,4,15,19,-1},
{28,8,4,15,19,-1},
{28,13,4,15,19,-1},
{28,11,4,15,19,-1},
{28,14,4,15,19,-1},
{27,17,3,15,-1},
{26,0,4,12,15,-1},
{26,23,4,12,15,-1},
{26,10,4,12,15,-1},
{26,8,4,12,15,-1},
{26,13,4,12,15,-1},
{26,11,4,12,15,-1},
{26,14,4,12,15,-1},
{25,14,3,16,-1},
{25,0,4,9,12,-1},
{25,23,4,9,12,-1},
{25,10,4,9,12,-1},
{25,8,4,9,12,-1},
{25,13,4,9,12,-1},
{25,11,4,9,12,-1},
{24,10,3,24,-1},
{24,22,3,30,-1},
{24,27,3,34,-1},
{24,29,3,36,-1},
{24,30,3,37,-1},
{24,31,3,38,-1},
{24,32,3,39,-1},
{24,33,3,40,-1},
{24,34,3,41,-1},
{24,35,3,42,-1},
{24,36,3,43,-1},
{24,37,3,44,-1},
{24,38,3,45,-1},
{23,13,3,19,-1},
{23,11,3,18,-1},
{23,0,4,7,9,-1},
{23,23,4,7,9,-1},
{23,10,4,7,9,-1},
{23,8,4,7,9,-1},
{22,10,3,21,-1},
{22,8,3,20,-1},
{22,0,5,-1},
{21,16,3,27,-1},
{21,10,3,24,-1},
{21,22,3,30,-1},
{21,27,3,34,-1},
{21,29,3,36,-1},
{21,30,3,37,-1},
{21,31,3,38,-1},
{21,32,3,39,-1},
{21,33,3,40,-1},
{21,34,3,41,-1},
{21,35,3,42,-1},
{21,36,3,43,-1},
{21,37,3,44,-1},
{21,38,3,45,-1},
{20,16,3,27,-1},
{20,10,3,24,-1},
{20,22,3,30,-1},
{20,27,3,34,-1},
{20,29,3,36,-1},
{20,30,3,37,-1},
{20,31,3,38,-1},
{20,32,3,39,-1},
{20,33,3,40,-1},
{20,34,3,41,-1},
{20,35,3,42,-1},
{20,36,3,43,-1},
{20,37,3,44,-1},
{20,38,3,45,-1},
{19,16,3,27,-1},
{19,10,3,24,-1},
{19,22,3,30,-1},
{19,27,3,34,-1},
{19,29,3,36,-1},
{19,30,3,37,-1},
{19,31,3,38,-1},
{19,32,3,39,-1},
{19,33,3,40,-1},
{19,34,3,41,-1},
{19,35,3,42,-1},
{19,36,3,43,-1},
{19,37,3,44,-1},
{19,38,3,45,-1},
{18,16,3,27,-1},
{18,10,3,24,-1},
{18,22,3,30,-1},
{18,27,3,34,-1},
{18,29,3,36,-1},
{18,30,3,37,-1},
{18,31,3,38,-1},
{18,32,3,39,-1},
{18,33,3,40,-1},
{18,34,3,41,-1},
{18,35,3,42,-1},
{18,36,3,43,-1},
{18,37,3,44,-1},
{18,38,3,45,-1},
{17,0,4,21,10,21,-1},
{17,23,4,21,10,21,-1},
{17,10,4,21,10,21,-1},
{17,8,4,21,10,21,-1},
{17,13,4,21,10,21,-1},
{17,11,4,21,10,21,-1},
{17,14,4,21,10,21,-1},
{17,20,4,21,10,21,-1},
{16,16,3,27,-1},
{16,10,3,24,-1},
{16,22,3,30,-1},
{16,27,3,34,-1},
{16,29,3,36,-1},
{16,30,3,37,-1},
{16,31,3,38,-1},
{16,32,3,39,-1},
{16,33,3,40,-1},
{16,34,3,41,-1},
{16,35,3,42,-1},
{16,36,3,43,-1},
{16,37,3,44,-1},
{16,38,3,45,-1},
{15,18,3,7,-1},
{14,10,3,24,-1},
{14,22,3,30,-1},
{14,27,3,34,-1},
{14,29,3,36,-1},
{14,30,3,37,-1},
{14,31,3,38,-1},
{14,32,3,39,-1},
{14,33,3,40,-1},
{14,34,3,41,-1},
{14,35,3,42,-1},
{14,36,3,43,-1},
{14,37,3,44,-1},
{14,38,3,45,-1},
{13,10,3,21,-1},
{13,8,3,20,-1},
{13,23,3,9,-1},
{12,0,4,25,25,28,-1},
{12,23,4,25,25,28,-1},
{12,10,4,25,25,28,-1},
{12,8,4,25,25,28,-1},
{12,13,4,25,25,28,-1},
{12,11,4,25,25,28,-1},
{12,14,4,25,25,28,-1},
{12,20,4,25,25,28,-1},
{12,38,4,25,25,28,-1},
{12,37,4,25,25,28,-1},
{12,36,4,25,25,28,-1},
{12,35,4,25,25,28,-1},
{12,34,4,25,25,28,-1},
{12,33,4,25,25,28,-1},
{12,32,4,25,25,28,-1},
{12,31,4,25,25,28,-1},
{12,30,4,25,25,28,-1},
{12,29,4,25,25,28,-1},
{12,27,4,25,25,28,-1},
{11,0,4,24,25,26,-1},
{11,23,4,24,25,26,-1},
{11,10,4,24,25,26,-1},
{11,8,4,24,25,26,-1},
{11,13,4,24,25,26,-1},
{11,11,4,24,25,26,-1},
{11,14,4,24,25,26,-1},
{11,20,4,24,25,26,-1},
{10,0,4,26,27,25,-1},
{10,23,4,26,27,25,-1},
{10,10,4,26,27,25,-1},
{10,8,4,26,27,25,-1},
{10,13,4,26,27,25,-1},
{10,11,4,26,27,25,-1},
{10,14,4,26,27,25,-1},
{10,20,4,26,27,25,-1},
{10,29,3,36,-1},
{10,30,3,37,-1},
{10,31,3,38,-1},
{10,32,3,39,-1},
{10,33,3,40,-1},
{10,34,3,41,-1},
{10,35,3,42,-1},
{10,36,3,43,-1},
{10,37,3,44,-1},
{10,38,3,45,-1},
{9,0,4,21,22,7,23,-1},
{9,23,4,21,22,7,23,-1},
{9,10,4,21,22,7,23,-1},
{9,8,4,21,22,7,23,-1},
{9,13,4,21,22,7,23,-1},
{9,11,4,21,22,7,23,-1},
{9,14,4,21,22,7,23,-1},
{9,20,4,21,22,7,23,-1},
{8,0,4,19,19,20,21,-1},
{8,23,4,19,19,20,21,-1},
{8,10,4,19,19,20,21,-1},
{8,8,4,19,19,20,21,-1},
{8,13,4,19,19,20,21,-1},
{8,11,4,19,19,20,21,-1},
{8,14,4,19,19,20,21,-1},
{8,20,4,19,19,20,21,-1},
{7,16,3,27,-1},
{7,10,3,24,-1},
{7,22,3,30,-1},
{7,27,3,34,-1},
{7,29,3,36,-1},
{7,30,3,37,-1},
{7,31,3,38,-1},
{7,32,3,39,-1},
{7,33,3,40,-1},
{7,34,3,41,-1},
{7,35,3,42,-1},
{7,36,3,43,-1},
{7,37,3,44,-1},
{7,38,3,45,-1},
{6,0,4,12,12,14,15,-1},
{6,23,4,12,12,14,15,-1},
{6,10,4,12,12,14,15,-1},
{6,8,4,12,12,14,15,-1},
{6,13,4,12,12,14,15,-1},
{6,11,4,12,12,14,15,-1},
{6,14,4,12,12,14,15,-1},
{5,14,3,16,-1},
{5,0,4,9,9,11,12,-1},
{5,23,4,9,9,11,12,-1},
{5,10,4,9,9,11,12,-1},
{5,8,4,9,9,11,12,-1},
{5,13,4,9,9,11,12,-1},
{5,11,4,9,9,11,12,-1},
{4,14,3,16,-1},
{4,0,4,9,9,13,12,-1},
{4,23,4,9,9,13,12,-1},
{4,10,4,9,9,13,12,-1},
{4,8,4,9,9,13,12,-1},
{4,13,4,9,9,13,12,-1},
{4,11,4,9,9,13,12,-1},
{3,13,3,19,-1},
{3,11,3,18,-1},
{3,0,4,7,7,8,9,-1},
{3,23,4,7,7,8,9,-1},
{3,10,4,7,7,8,9,-1},
{3,8,4,7,7,8,9,-1},
{2,13,3,19,-1},
{2,11,3,18,-1},
{2,0,4,7,7,10,9,-1},
{2,23,4,7,7,10,9,-1},
{2,10,4,7,7,10,9,-1},
{2,8,4,7,7,10,9,-1},
{1,0,4,15,16,17,18,15,-1},
{1,23,4,15,16,17,18,15,-1},
{1,10,4,15,16,17,18,15,-1},
{1,8,4,15,16,17,18,15,-1},
{1,13,4,15,16,17,18,15,-1},
{1,11,4,15,16,17,18,15,-1},
{1,14,4,15,16,17,18,15,-1},
{0,16,3,27,-1},
{0,10,3,24,-1},
{0,22,3,30,-1},
{0,27,3,34,-1},
{0,29,3,36,-1},
{0,30,3,37,-1},
{0,31,3,38,-1},
{0,32,3,39,-1},
{0,33,3,40,-1},
{0,34,3,41,-1},
{0,35,3,42,-1},
{0,36,3,43,-1},
{0,37,3,44,-1},
{0,38,3,45,-1}
};
public
void init() {
applet = this;
setBackground(Color.lightGray);
setFont(new Font("Courier", Font.BOLD, 12));
LogFontLayout lfLayout = new LogFontLayout(this);
setLayout(lfLayout);
pButton1 = new Button("log");
add("17 35 32 12", pButton1);
pEdit1 = new TextField(" (-- 3 ) * 4");
add("17 17 201 14", pEdit1);
pButton2 = new Button("(");
add("54 35 32 12", pButton2);
pButton3 = new Button(")");
add("91 35 32 12", pButton3);
pButton4 = new Button("^");
add("130 35 32 12", pButton4);
pButton5 = new Button("7");
add("17 51 32 12", pButton5);
pButton6 = new Button("8");
add("55 51 32 12", pButton6);
pButton7 = new Button("9");
add("93 51 32 12", pButton7);
pButton8 = new Button("+");
add("131 51 32 12", pButton8);
pButton9 = new Button("4");
add("17 67 32 12", pButton9);
pButton10 = new Button("5");
add("55 67 32 12", pButton10);
pButton11 = new Button("6");
add("93 67 32 12", pButton11);
pButton12 = new Button("-");
add("131 67 32 12", pButton12);
pButton13 = new Button("1");
add("17 83 32 12", pButton13);
pButton14 = new Button("2");
add("55 83 32 12", pButton14);
pButton15 = new Button("3");
add("93 83 32 12", pButton15);
pButton16 = new Button("*");
add("131 83 32 12", pButton16);
pButton17 = new Button("0");
add("17 99 32 12", pButton17);
pButton18 = new Button(".");
add("55 99 32 12", pButton18);
pButton19 = new Button("Compute");
add("93 99 32 12", pButton19);
pButton20 = new Button("/");
add("131 99 32 12", pButton20);
pStatic01 = new Label("LR1 Calculator 1.0, by EllenT,all rights reserved");
add("5 3 269 12", pStatic01);
pButton21 = new Button("Help");
add("93 117 69 12", pButton21);
pStatic02 = new Label("substraction or negation");
add("167 66 100 14", pStatic02);
pStatic03 = new Label("addition");
add("166 51 85 12", pStatic03);
pStatic04 = new Label("exponential");
add("165 35 94 12", pStatic04);
pStatic05 = new Label("multiplication");
add("167 83 95 12", pStatic05);
pStatic06 = new Label("division");
add("168 99 94 12", pStatic06);
pButton22 = new Button("Replay");
add("17 117 70 12", pButton22);
// Size in logical units
resize(getLayout().preferredLayoutSize(this));
pEdit1.setCaretPosition( pEdit1.getText().length() );
pEdit1.requestFocus();
}
public Dimension minimumSize() {
LayoutManager layoutMgr = getLayout();
if (layoutMgr instanceof LogFontLayout) {
// Convert from logical units to absolute coordinates
int w = initialSize.width;
int h = initialSize.height;
LogFontLayout layout = (LogFontLayout)layoutMgr;
return new Dimension(layout.duX(w), layout.duY(h));
}
return new Dimension(initialSize);
}
public boolean handleEvent(Event e) {
if (e.target == pEdit1 && e.id == Event.GOT_FOCUS) {
return false;
}
return super.handleEvent(e);
}
public Frame getFrame(Container c) {
if (c instanceof Frame || c == null)
return((Frame)c);
else
return(getFrame(c.getParent()));
}
public boolean action(Event evt, Object obj) {
if (evt.target == pButton1) {
String tempS = pButton1.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton2) {
String tempS = pButton2.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton3) {
String tempS = pButton3.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton4) {
String tempS = pButton4.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton5) {
String tempS = pButton5.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton6) {
String tempS = pButton6.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton7) {
String tempS = pButton7.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton8) {
String tempS = pButton8.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton9) {
String tempS = pButton9.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton10) {
String tempS = pButton10.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton11) {
String tempS = pButton11.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton12) {
String tempS = pButton12.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton13) {
String tempS = pButton13.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton14) {
String tempS = pButton14.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton15) {
String tempS = pButton15.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton16) {
String tempS = pButton16.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton17) {
String tempS = pButton17.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton18) {
String tempS = pButton18.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if ((evt.target == pButton19) || (evt.target == pEdit1)) {
String InputString = pEdit1.getText();
int[] symbol_stack = new int[900];
double[] compute_stack = new double[200];
int[] N_length_stack = new int[200];
int symbol_stack_size = 0,
compute_stack_size = 0,
N_length_stack_size = 0,
done = 0, T, i, j, k, a, b, sleep_length = 1500;
Character c;
double f1, f2;
symbol_stack[0] = 0;
symbol_stack_size = 1;
compute_stack[0] = 0;
compute_stack_size = 1;
if (InputString.length() == 0)
InputString = new String("0");
// delete spaces.
read_at = 0;
while ((read_at < InputString.length()) && (InputString.charAt(read_at) == ' '))
read_at++;
// find the index of the read input.
a = 0;
if (read_at < InputString.length()) {
while ((a < SymbolTableSize) &&
(Symbol[a].compareTo( InputString.substring(read_at, read_at + 1).toUpperCase() ) != 0) )
a++;
if (a >= SymbolTableSize)
a = -1;
}
while (done != 1) {
// search the action table: action[symbol_stack[sym_bol_stack_size - 1], a]
i = 0;
while ((i < ActionTableSize) &&
((ActionTable[i][0] != symbol_stack[symbol_stack_size - 1]) ||
(ActionTable[i][1] != a))) {
i++;
}
if (i >= ActionTableSize) {
// error!!
PreviousString = new String( pEdit1.getText() );
pEdit1.setText( "Syntax Error!!!" );
try {
Thread.sleep(sleep_length);
}
catch (InterruptedException e) {
}
pEdit1.setText( PreviousString );
pEdit1.setCaretPosition(read_at);
pEdit1.select( read_at, read_at + 1);
done = 1;
}
else if (Symbol[ActionTable[i][2]].compareTo( "_shift" )== 0) {
symbol_stack[symbol_stack_size] = a;
symbol_stack_size++;
symbol_stack[symbol_stack_size] = ActionTable[i][3];
symbol_stack_size++;
// delete spaces
j = InputString.length();
read_at++;
while ((read_at < j) && (InputString.charAt(read_at) == ' '))
read_at++;
a = 0; // the "end" symbol
if (read_at < InputString.length()) {
while ((a < SymbolTableSize) &&
(Symbol[a].compareTo( InputString.substring(read_at, read_at + 1).toUpperCase() ) != 0))
a++;
if (a >= SymbolTableSize)
a = -1;
}
if (a == -1) {
PreviousString = new String( pEdit1.getText() );
pEdit1.setText( "Syntax Error!!!" );
try {
Thread.sleep(sleep_length);
}
catch (InterruptedException e) {
}
pEdit1.setText( PreviousString );
pEdit1.setCaretPosition(read_at);
pEdit1.select( read_at, read_at + 1 );
done = 1;
}
}
else if (Symbol[ActionTable[i][2]].compareTo( "_reduce" )== 0) {
b = 4;
while (ActionTable[i][b] >= 0)
b++;
symbol_stack_size -= (2 * (b - 4));
symbol_stack[symbol_stack_size] = ActionTable[i][3];
symbol_stack_size++;
j = 0;
while ((j < GotoTableSize) &&
((GotoTable[j][0] != symbol_stack[symbol_stack_size - 2]) ||
(GotoTable[j][1] != symbol_stack[symbol_stack_size - 1]))) {
j++;
}
symbol_stack[symbol_stack_size] = GotoTable[j][2];
symbol_stack_size++;
// all the reduction rules' translation
if (Symbol[ActionTable[i][3]].compareTo( "D" ) == 0) {
compute_stack[compute_stack_size] = 1.0 * Character.digit(Symbol[ActionTable[i][4]].charAt(0), 10);
compute_stack_size++;
N_length_stack[N_length_stack_size] = 1;
N_length_stack_size++;
}
else if (Symbol[ActionTable[i][3]].compareTo( "N" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "N" ) == 0) {
compute_stack_size--;
compute_stack[compute_stack_size - 1] =
10.0*compute_stack[compute_stack_size - 1] + compute_stack[compute_stack_size];
N_length_stack_size--;
N_length_stack[N_length_stack_size - 1] += N_length_stack[N_length_stack_size];
}
}
else if (Symbol[ActionTable[i][3]].compareTo( "Q" ) == 0) {
compute_stack[compute_stack_size - 1] /=
Math.pow( 10.0, 1.0 * N_length_stack[N_length_stack_size - 1] );
N_length_stack_size--;
}
else if (Symbol[ActionTable[i][3]].compareTo( "P" ) == 0) {
compute_stack_size--;
compute_stack[compute_stack_size - 1] += compute_stack[compute_stack_size];
N_length_stack_size--;
}
else if (Symbol[ActionTable[i][3]].compareTo( "U" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "N" ) == 0)
N_length_stack_size--;
else if (Symbol[ActionTable[i][4]].compareTo( "-" ) == 0)
compute_stack[compute_stack_size - 1] *= -1.0;
}
else if (Symbol[ActionTable[i][3]].compareTo( "F" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "F" ) == 0) {
compute_stack_size--;
compute_stack[compute_stack_size - 1] *= Math.pow(10.0, compute_stack[compute_stack_size]);
}
}
else if (Symbol[ActionTable[i][3]].compareTo( "X" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "X" ) == 0) {
compute_stack_size--;
compute_stack[compute_stack_size - 1] =
Math.pow( compute_stack[compute_stack_size - 1],
compute_stack[compute_stack_size]);
}
}
else if (Symbol[ActionTable[i][3]].compareTo( "I" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "L" ) == 0) {
if (compute_stack[compute_stack_size - 1] >= 0)
compute_stack[compute_stack_size - 1] = Math.log( compute_stack[compute_stack_size - 1] );
else {
PreviousString = new String( pEdit1.getText() );
pEdit1.setText( "Error: log(a negative number)!!!" );
try {
Thread.sleep(sleep_length);
}
catch (InterruptedException e) {
}
pEdit1.setText( PreviousString );
pEdit1.setCaretPosition(read_at);
pEdit1.select( read_at, read_at + 1 );
done = 1;
}
}
}
else if (Symbol[ActionTable[i][3]].compareTo( "M" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "M" ) == 0) {
if (Symbol[ActionTable[i][5]].compareTo( "/" ) == 0) {
if (compute_stack[compute_stack_size - 1] == 0) {
PreviousString = new String( pEdit1.getText() );
pEdit1.setText( "Error: divided by zero!!!" );
try {
Thread.sleep(sleep_length);
}
catch (InterruptedException e) {
}
pEdit1.setText( PreviousString );
pEdit1.setCaretPosition(read_at);
pEdit1.select( read_at, read_at + 1 );
done = 1;
}
else {
compute_stack_size--;
compute_stack[compute_stack_size - 1] /= compute_stack[compute_stack_size];
}
}
else {
compute_stack_size--;
compute_stack[compute_stack_size - 1] *= compute_stack[compute_stack_size];
}
}
}
else if (Symbol[ActionTable[i][3]].compareTo( "C" ) == 0) {
if (Symbol[ActionTable[i][4]].compareTo( "C" ) == 0) {
if (Symbol[ActionTable[i][5]].compareTo( "-" ) == 0) {
compute_stack_size--;
compute_stack[compute_stack_size - 1] -= compute_stack[compute_stack_size];
}
else {
compute_stack_size--;
compute_stack[compute_stack_size - 1] += compute_stack[compute_stack_size];
}
}
}
}
else if (Symbol[ActionTable[i][2]].compareTo( "_accept" )== 0) {
PreviousString = new String( pEdit1.getText() );
pEdit1.setText( Double.toString(compute_stack[compute_stack_size - 1]) );
pEdit1.setCaretPosition( pEdit1.getText().length() );
done = 1;
}
}
pEdit1.requestFocus();
}
else if (evt.target == pButton20) {
String tempS = pButton20.getLabel();
int start = pEdit1.getCaretPosition();
pEdit1.setText(
pEdit1.getText().substring( 0, start) +
tempS +
pEdit1.getText().substring( start )
);
pEdit1.setCaretPosition( start + tempS.length() );
pEdit1.requestFocus();
}
else if (evt.target == pButton21) {
Dialog1 dDialog1= new Dialog1(applet, getFrame(this), "About", true);
dDialog1.show();
pEdit1.requestFocus();
}
else if (evt.target == pButton22) {
pEdit1.setText( PreviousString );
pEdit1.setCaretPosition( PreviousString.length() );
pEdit1.requestFocus();
}
return true;
}
}
Last edited by EllenT; Sep 5th, 2007 at 5:51 pm. Reason: add icon
As you said it is a dificult problem and it is your so please do your homework and only if you get into certain difficulties make another post. We are not here to do whole your homework. More info here
Last edited by peter_budo; Sep 5th, 2007 at 7:02 pm.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Nov 2008
Posts: 1
Reputation:
Solved Threads: 0
pls can u tell me how to convert java application(swing jframe...) into applet with two or three lines.
I tried that mtd first mtd; cant figure out this
- creating the applet as a JApplet not component
- calling init() explicitly
- using setVisible(true) & setSize(x,y)
if u could show me the code dat would be great help!
tx
I tried that mtd first mtd; cant figure out this
- creating the applet as a JApplet not component
- calling init() explicitly
- using setVisible(true) & setSize(x,y)
if u could show me the code dat would be great help!
tx
![]() |
Similar Threads
- how to change application into an applet and application (Java)
- is it possible to run the java application in a mysql linux server (Java)
- Run a console application using GUI (C++)
- Applet or Application? (Java)
Other Threads in the Java Forum
- Previous Thread: Mouse Drag Zooming
- Next Thread: J2ME Certification Tutorial
Views: 10808 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addressbook android api append apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component csv database detection draw eclipse error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia linux list loop map method methods mobile netbeans newbie number object objects oracle oriented os panel print problem program programming project projects recursion replaydirector reporting researchinmotion return robot scanner score screen se server set size sms socket sort sql stream string swing test threads time transfer tree ubuntu windows






