/* A basic implementation of the JFrame class. */ package application.basic; import java.awt.Dimension; import java.awt.Font; import java.awt.Insets; import java.util.Hashtable; import java.util.Vector; import controlledparts.StateContainer; import controlledparts.ControlledButton; import controlledparts.FrameWithControlledButton; import controlledparts.SelectedButton; /** * This code was generated using CloudGarden's Jigloo * SWT/Swing GUI Builder, which is free for non-commercial * use. If Jigloo is being used commercially (ie, by a corporation, * company or business for any purpose whatever) then you * should purchase a license for each developer using Jigloo. * Please visit www.cloudgarden.com for details. * Use of Jigloo implies acceptance of these licensing terms. * ************************************* * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED * for this machine, so Jigloo or this code cannot be used legally * for any corporate or commercial purpose. * ************************************* */ public class BasicExampleListFrame extends javax.swing.JFrame implements FrameWithControlledButton, StateContainer { Hashtable programExample; public int getState() { return this.currentState; } private int currentState; public void setState(int i) { frame.exampleButton.setText(((ControlledButton)(buttons.elementAt(i))).getText()); frame.currentExample=(String)(programs.elementAt(i)); this.currentState=i; } public boolean isControlledByLocalUser() { // This method is derived from interface FrameWithControlledButton // to do: code goes here if(frame==null) return true; return frame.isControlledByLocalUser(); } public boolean isDirectOperation() { // This method is derived from interface FrameWithControlledButton // to do: code goes here if(frame==null) return true; return frame.isDirectOperation(); } public void sendEvent(String x) { frame.sendEvent("bex."+x); } public void unfocusButton(int i) { SelectedButton button=(SelectedButton)(buttons.elementAt(i)); // button.controlledButton_mouseExited(null); button.unFocus(); } public void focusButton(int i) { SelectedButton button=(SelectedButton)(buttons.elementAt(i)); // button.controlledButton_mouseEntered(null); button.focus(); } public void clickButton(int i) { ControlledButton b=(ControlledButton)(buttons.elementAt(i)); b.click(); this.mouseClickedAtButton(i); } public void setFrame(BasicFrame f) { frame=f; } private BasicFrame frame; public Vector programs; public Vector buttons; public void mouseExitedAtButton(int i) { // This method is derived from interface SelectButtonsFrame // to do: code goes here // frame.sendEvent("bex.btn.exit("+i+")\n"); } public void mouseEnteredAtButton(int i) { // This method is derived from interface SelectButtonsFrame // to do: code goes here // frame.sendEvent("bex.btn.enter("+i+")\n"); } public void mouseClickedAtButton(int i) { // This method is derived from interface SelectButtonsFrame // to do: code goes here ControlledButton b=(ControlledButton)(buttons.elementAt(i)); if(b.getText().equals("cancel")) { this.hide(); return; } if(frame!=null){ this.setState(i); } this.hide(); } public BasicExampleListFrame() { // This code is automatically generated by Visual Cafe when you add // components to the visual environment. It instantiates and initializes // the components. To modify the code, only use code syntax that matches // what Visual Cafe can generate, or Visual Cafe may be unable to back // parse your Java file into its visual environment. //{{INIT_CONTROLS getContentPane().setLayout(null); getContentPane().setBackground(new java.awt.Color(204,204,204)); setSize(180,334); setVisible(false); factorialButton.setText("factorial"); factorialButton.setActionCommand("factorial"); getContentPane().add(factorialButton); factorialButton.setBackground(new java.awt.Color(204,204,204)); factorialButton.setForeground(java.awt.Color.black); factorialButton.setFont(new Font("Dialog", Font.BOLD, 12)); factorialButton.setBounds(12,12,156,24); fibonacciButton.setText("fibonacci"); fibonacciButton.setActionCommand("fibonacci"); getContentPane().add(fibonacciButton); fibonacciButton.setBackground(new java.awt.Color(204,204,204)); fibonacciButton.setForeground(java.awt.Color.black); fibonacciButton.setFont(new Font("Dialog", Font.BOLD, 12)); fibonacciButton.setBounds(12,36,156,24); lines1Button.setText("lines1"); lines1Button.setActionCommand("lines1"); getContentPane().add(lines1Button); lines1Button.setBackground(new java.awt.Color(204,204,204)); lines1Button.setForeground(java.awt.Color.black); lines1Button.setFont(new Font("Dialog", Font.BOLD, 12)); lines1Button.setBounds(12,60,156,24); sincurveButton.setText("sincurve"); sincurveButton.setActionCommand("sincurve"); getContentPane().add(sincurveButton); sincurveButton.setBackground(new java.awt.Color(204,204,204)); sincurveButton.setForeground(java.awt.Color.black); sincurveButton.setFont(new Font("Dialog", Font.BOLD, 12)); sincurveButton.setBounds(12,84,156,24); gaussButton.setText("gauss"); gaussButton.setActionCommand("gauss"); getContentPane().add(gaussButton); gaussButton.setBackground(new java.awt.Color(204,204,204)); gaussButton.setForeground(java.awt.Color.black); gaussButton.setFont(new Font("Dialog", Font.BOLD, 12)); gaussButton.setBounds(12,108,156,24); hanoiButton.setText("hanoi"); hanoiButton.setActionCommand("hanoi"); getContentPane().add(hanoiButton); hanoiButton.setBackground(new java.awt.Color(204,204,204)); hanoiButton.setForeground(java.awt.Color.black); hanoiButton.setFont(new Font("Dialog", Font.BOLD, 12)); hanoiButton.setBounds(12,132,156,24); sieveButton.setText("sieve"); sieveButton.setActionCommand("eratos"); getContentPane().add(sieveButton); sieveButton.setBackground(new java.awt.Color(204,204,204)); sieveButton.setForeground(java.awt.Color.black); sieveButton.setFont(new Font("Dialog", Font.BOLD, 12)); sieveButton.setBounds(12,156,156,24); s2iButton.setText("s2i"); s2iButton.setActionCommand("s2i"); getContentPane().add(s2iButton); s2iButton.setBackground(new java.awt.Color(204,204,204)); s2iButton.setForeground(java.awt.Color.black); s2iButton.setFont(new Font("Dialog", Font.BOLD, 12)); s2iButton.setBounds(12,180,156,24); mathButton.setText("math-fun"); mathButton.setActionCommand("math-fun"); getContentPane().add(mathButton); mathButton.setBackground(new java.awt.Color(204,204,204)); mathButton.setForeground(java.awt.Color.black); mathButton.setFont(new Font("Dialog", Font.BOLD, 12)); mathButton.setBounds(12,204,156,24); associateButton.setText("associate"); associateButton.setActionCommand("associate"); getContentPane().add(associateButton); associateButton.setBackground(new java.awt.Color(204,204,204)); associateButton.setForeground(java.awt.Color.black); associateButton.setFont(new Font("Dialog", Font.BOLD, 12)); associateButton.setBounds(12,228,156,24); cancelButton.setText("cancel"); cancelButton.setActionCommand("cancel"); getContentPane().add(cancelButton); cancelButton.setBackground(new java.awt.Color(204,204,204)); cancelButton.setForeground(java.awt.Color.black); cancelButton.setFont(new Font("Dialog", Font.BOLD, 12)); cancelButton.setBounds(12,288,156,24); while1Button.setText("while-ex1"); while1Button.setActionCommand("associate"); getContentPane().add(while1Button); while1Button.setBackground(new java.awt.Color(204,204,204)); while1Button.setForeground(java.awt.Color.black); while1Button.setFont(new Font("Dialog", Font.BOLD, 12)); while1Button.setBounds(12,252,156,24); //}} //{{INIT_MENUS //}} //{{REGISTER_LISTENERS SymAction lSymAction = new SymAction(); // factorialButton.addActionListener(lSymAction); //}} programs=new Vector(); buttons=new Vector(); buttons.addElement(this.factorialButton); programs.addElement("factorial"); buttons.addElement(this.fibonacciButton); programs.addElement("fibonacci"); buttons.addElement(this.lines1Button); programs.addElement("lines1"); buttons.addElement(this.sincurveButton); programs.addElement("sincurv"); buttons.addElement(this.gaussButton); programs.addElement("gauss"); buttons.addElement(this.hanoiButton); programs.addElement("hanoi"); buttons.addElement(this.sieveButton); programs.addElement("sieve"); buttons.addElement(this.s2iButton); programs.addElement("s2i"); buttons.addElement(this.mathButton); programs.addElement("math-fun"); buttons.addElement(this.associateButton); programs.addElement("associate"); buttons.addElement(this.while1Button); programs.addElement("while-ex1"); buttons.addElement(this.cancelButton); this.programExample=new Hashtable(); this.programExample.put("sieve", "'Prime numbers\n"+ "' by the Sieve of Eratosthenes\n"+ "'\n"+ "' t.yamanoue, May, 1999\n"+ "'\n"+ "dim s\n"+ "n=100\n"+ "for i=1 to n:s(i)=1:next i\n"+ "'\n"+ "for i=2 to n\n"+ "for j=i to n/i:s(i*j)=0:next j\n"+ "next i\n"+ "'\n"+ "for i=2 to n\n"+ "if s(i)=1 then ? \"\"+i+\" is a prime number.\"\n"+ "next i" ); this.programExample.put("factorial", "'factorial\n"+ "'\n"+ "' t.yamanoue, May, 1999\n"+ "'\n"+ "def factorial(x)= if x=1 then 1\n"+ "else x*factorial(x-1)\n"+ "'\n"+ "' an example of this function usage\n"+ "'\n"+ "' ?factorial(5)\n"+ "' 120\n"+ "' OK\n"+ "'\n"+ "for i=1 to 7\n"+ "?factorial(i)\n"+ "next i" ); this.programExample.put("fibonacci", "'fibonacci\n"+ "'\n"+ "' t.yamanoue, May, 1999\n"+ "'\n"+ "def fib(x)= if x=0 then 0\n"+ "else if x=1 then 1\n"+ "else fib(x-1)+fib(x-2)\n"+ "'\n"+ "' an example of this function usage\n"+ "'\n"+ "' ?fib(5)\n"+ "' 5\n"+ "' OK\n"+ "for i=1 to 8\n"+ "?fib(i)\n"+ "next i\n" ); this.programExample.put("associate", "'example of an associate array\n"+ "dim a\n"+ "'this can be used as a dictionary\n"+ "a(\"dog\")=\"inu\"\n"+ "a(\"cat\")=\"neko\"\n"+ "?a(\"dog\")\n"+ "?a(\"cat\")\n"+ "'this can be used as a variable dimension array\n"+ "a(1)=\"abc\"\n"+ "a(1,2)=\"efg\"\n"+ "?a(1)\n"+ "?a(1,2)\n" ); this.programExample.put("minus", "x=1234\n"+ "y=2020\n"+ "z=3456\n"+ "w=4567\n"+ "?\"x-y=\"+(x-y)+\" x-z=\"+(x-z)+\" x-w=\"+(x-w)\n"+ "?\"y-x=\"+(y-x)+\" y-z=\"+(y-z)+\" y-w=\"+(y-w)\n"+ "?\"z-x=\"+(z-x)+\" z-y=\"+(z-y)+\" z-y=\"+(z-y)\n"+ "?\"w-x=\"+(w-x)+\" w-y=\"+(w-y)+\" w-z=\"+(w-z)\n" ); this.programExample.put("blank",""); this.programExample.put("math-fun", "'pre-defined Mathematical functions\n"+ "'\n"+ "' t. yamanoue, May, 1999\n"+ "'\n"+ "Pi=3.14159265358979\n"+ "? \"sin(Pi/6)=\"+ sin(Pi/6)\n"+ "? \"cos(Pi/6)=\"+ cos(Pi/6)\n"+ "? \"tan(Pi/4)=\"+ tan(Pi/4)\n"+ "? \"4*atan(1.0)=\"+ 4*atan(1.0)\n"+ "? \"sqrt(2.0)=\"+ sqrt(2.0)\n"+ "? \"exp(1.0)=\"+ exp(1.0)\n"+ "? \"exp(0.0)=\"+ exp(0.0)\n"+ "? \"log(1.0)=\"+ log(1.0)\n"+ "? \"exp(3.0*log(2.0))=\"+ exp(3.0*log(2.0))\n"+ "? \"mod(8,3)=\"+ mod(8,3)" ); this.programExample.put("gauss", "' solving a linear system by\n"+ "' Gaussian Elimination Method\n"+ "'\n"+ "' by t.yamanoue, May, 1999\n"+ "'\n"+ "' dim a is the linear system\n"+ "dim a\n"+ "a(1,1)=1.0:a(1,2)=0.0:a(1,3)=0.0:a(1,4)=3.0\n"+ "a(2,1)=0.0:a(2,2)=1.0:a(2,3)=0.0:a(2,4)=4.0\n"+ "a(3,1)=0.0:a(3,2)=0.0:a(3,3)=1.0:a(3,4)=5.0\n"+ "'\n"+ "' n:size of the linear system\n"+ "n=3\n"+ "for i=1 to n\n"+ "p=a(i,i)\n"+ "for j=i to n+1:a(i,j)=a(i,j)/p:next j\n"+ "for k=1 to n\n"+ "if i<>k then\n"+ "{\n"+ "p=a(k,i)\n"+ "for j=i to n+1\n"+ "a(k,j)=a(k,j)-p*a(i,j)\n"+ "next j\n"+ "}\n"+ "next k\n"+ "next i\n"+ "'\n"+ "' Output the solution\n"+ "for i=1 to n\n"+ "? a(i,n+1)\n"+ "next i\n" ); this.programExample.put("lines1", "' Line Example 1.\n"+ "'\n"+ "' t.yamanoue, May,1999\n"+ "'\n"+ "w=200\n"+ "for i=0 to w step 10\n"+ "line(0,i)-(i,w),1\n"+ "next i" ); this.programExample.put("sincurv", "' draw a sin curve\n"+ "' t.yamanoue, may,1999\n"+ "'\n"+ "' the sin function\n"+ "def f(x)=sin(x)\n"+ "'\n"+ "' transform x value to the x value on the graphics plane\n"+ "def gx(x)=x+10\n"+ "'\n"+ "' transform y value to the y value on the graphics plane\n"+ "def gy(y)=ymax-y\n"+ "'\n"+ "' x-min, x-max, y-min, y-max\n"+ "xmin=0:xmax=300\n"+ "ymin=0:ymax=150\n"+ "'\n"+ "a=ymax/2\n"+ "Pi=3.14159265\n"+ "'\n"+ "' draw the x axis\n"+ "line (gx(xmin),gy(ymin))-(gx(xmax),gy(ymin))\n"+ "t=0\n"+ "s=10\n"+ "pset(gx(t),gy(a*f(2*Pi*t/xmax)))\n"+ "for t=s to xmax step s\n"+ "line -(gx(t),gy(a*f(2*Pi*t/xmax)))\n"+ "next t\n" ); this.programExample.put("hanoi", "def hanoi(n,a,b,c)={\n"+ " if n>0 then\n"+ " {\n"+ " call hanoi(n-1,a,c,b);\n"+ " ? a+\" to \"+c;\n"+ " call hanoi(n-1,b,a,c);\n"+ " }\n"+ "}\n"+ "call hanoi(3,\"a\",\"b\",\"c\");\n" ); int numberOfButtons=buttons.size(); for(int i=0;i