1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
// charles vidal <vidalc@club-internet.fr>
// the GUI definition and the handler event
import java.applet.*;
import java.awt.*;
import java.lang.Runtime;
public class xlockFrame extends Applet {
public static final int nbcoption=9;
public static final int nbbooleanopt=14;
Button blaunch;
Button blaunchinw;
Button bquit;
Choice coptions;
TextField foroptions;
List lst ;
int currentOption=0;
MyFrameError mfe;
boolean isinapp=false;
// Array of option name
String[] nomOption={"Name program",
"File",
"Message Password",
"Message Valid",
"Message Invalid",
"Prompt",
"Fonts",
"Geometry","Display"};
String[] valueOption={"","","","","","","","",""};
String[] cmdlineOption={"-program","-messagefile","-password","-validate","-invalid","","-font","-geometry","-display"};
// Array of option boolean name
String[] booleanOption={
"-mono ",
"-nolock ",
"-remote ",
"-allowroot ",
"-enablesaver ",
"-allowaccess ",
"-grabmouse ",
"-echokeys ",
"-usefirst ",
"-verbose ",
"-inroot ",
"-timeelapsed ",
"-install ",
"-use3d "};
Checkbox bopt[]=new Checkbox[15];
public void init()
{
Frame theAppWindow = new Frame("xlockFrame");
Panel Panel1 = new Panel();
Panel Panel2 = new Panel();
Panel Panel3 = new Panel();
setLayout(new BorderLayout(10,10));
lst = new List();
coptions=new Choice();
for (int i=0;i<nbcoption;i++)
coptions.addItem(nomOption[i]);
Panel3.add(coptions);
foroptions = new TextField(20);
Panel3.add(foroptions);
add("North", Panel3);
add("Center",lst);
lst.addItem("ant");
lst.addItem("ball");
lst.addItem("bat");
lst.addItem("blot");
lst.addItem("bouboule");
lst.addItem("bounce");
lst.addItem("braid");
lst.addItem("bubble");
lst.addItem("bug");
lst.addItem("cage");
lst.addItem("cartoon");
lst.addItem("clock");
lst.addItem("coral");
lst.addItem("crystal");
lst.addItem("daisy");
lst.addItem("dclock");
lst.addItem("deco");
lst.addItem("demon");
lst.addItem("dilemma");
lst.addItem("drift");
lst.addItem("eyes");
lst.addItem("fadeplot");
lst.addItem("flag");
lst.addItem("flame");
lst.addItem("forest");
lst.addItem("galaxy");
lst.addItem("gears");
lst.addItem("grav");
lst.addItem("helix");
lst.addItem("hop");
lst.addItem("hyper");
lst.addItem("ico");
lst.addItem("ifs");
lst.addItem("image");
lst.addItem("julia");
lst.addItem("kaleid");
lst.addItem("laser");
lst.addItem("life");
lst.addItem("life1d");
lst.addItem("life3d");
lst.addItem("lisa");
lst.addItem("lissie");
lst.addItem("loop");
lst.addItem("marquee");
lst.addItem("mandelbrot");
lst.addItem("maze");
lst.addItem("moebius");
lst.addItem("morph3d");
lst.addItem("mountain");
lst.addItem("munch");
lst.addItem("nose");
lst.addItem("pacman");
lst.addItem("penrose");
lst.addItem("petal");
lst.addItem("pipes");
lst.addItem("puzzle");
lst.addItem("pyro");
lst.addItem("qix");
lst.addItem("roll");
lst.addItem("rotor");
lst.addItem("rubik");
lst.addItem("shape");
lst.addItem("sierpinski");
lst.addItem("slip");
lst.addItem("sphere");
lst.addItem("spiral");
lst.addItem("spline");
lst.addItem("sproingies");
lst.addItem("stairs");
lst.addItem("star");
lst.addItem("strange");
lst.addItem("superquadrics");
lst.addItem("swarm");
lst.addItem("swirl");
lst.addItem("triangle");
lst.addItem("tube");
lst.addItem("turtle");
lst.addItem("vines");
lst.addItem("voters");
lst.addItem("wator");
lst.addItem("wire");
lst.addItem("world");
lst.addItem("worm");
lst.addItem("blank");
lst.addItem("bomb");
lst.addItem("random");
lst.select(0);
add("East", Panel1);
Panel1.setLayout(new GridLayout(15,1));
for (int i=0;i<nbbooleanopt;i++)
{ bopt[i]=new Checkbox(booleanOption[i],null,false);
Panel1.add(bopt[i]);
}
add("South", Panel2);
blaunch=new Button("Launch");
blaunchinw=new Button("Launch in window");
bquit=new Button("Quit");
Panel2.add(blaunch);
Panel2.add(blaunchinw);
Panel2.add(bquit);
}
public String getBooleanOption()
{
String result="";
for (int i=0;i<nbbooleanopt;i++)
{if (bopt[i].getState()) result=result.concat(booleanOption[i]);
}
return (result);
}
public boolean action (Event evt, Object arg)
{
Runtime r=Runtime.getRuntime();
if (isinapp)
mfe=new MyFrameError("An error occured , You can't launch xlock");
else
mfe=new MyFrameError("An error occured , You can't launch xlock");
//mfe=new MyFrameError("You can't launch by a Browser");
mfe.resize(350,150);
if (evt.target == blaunch || evt.target == blaunchinw)
{
String label= (String) arg;
String cmdlinexlock="xlock ";
if (evt.target == blaunchinw ) cmdlinexlock=cmdlinexlock.concat("-inwindow ");
for (int i=0;i<nbcoption;i++)
{
if (!valueOption[i].equals(""))
{
cmdlinexlock=cmdlinexlock.concat(cmdlineOption[i]+" "+valueOption[i]+" ");
}
}
cmdlinexlock=cmdlinexlock.concat(getBooleanOption());
cmdlinexlock=cmdlinexlock.concat(" -mode ");
cmdlinexlock=cmdlinexlock.concat(lst.getSelectedItem());
try {
System.out.println(cmdlinexlock);
r.getRuntime().exec(cmdlinexlock); }
catch ( Exception e )
{mfe.show();}
return true;}
else
if (evt.target == coptions)
{
String label= (String) arg;
valueOption[currentOption]=foroptions.getText();
for (int i=0;i<nbcoption;i++)
{
if (nomOption[i].equals(label))
{foroptions.setText(valueOption[i]);
currentOption=i;
}
}
}
else
if (evt.target == bquit) {System.exit(0);}
else if (evt.target instanceof Checkbox)
{
return true;
}
else
if (evt.target == foroptions)
{
String label= (String) arg;
valueOption[currentOption]=label;
return true;
}
return false;
}
public void SetInAppl()
{
isinapp=true;
}
}
class MyFrameError extends Frame {
Label l;
Button b_ok;
MyFrameError (String erreur) {
setLayout(new BorderLayout());
l=new Label(erreur,Label.CENTER);
add("Center",l);
b_ok=new Button("Ok");
add("South",b_ok);
setTitle(erreur);
setCursor(HAND_CURSOR);
}
public boolean action (Event evt,Object arj){
if (evt.target instanceof Button)
{
this.hide();
return (true);
}
return (false);
}
}
|