"Welcome!" applet

Other applets

You can see this applet in work on the top of my homepage. Applet draws the computer and shows the appearance of the specified text string on its display. Typing text can be selected from the list; the animation can be paused.

You can use this applet source and change it free, but You must conserve the lines about the author. Please, send me URL of Your page with applet to E-mail address eremin@hotbot.com.

/* (C) Evgeny Eremin (Perm, Russia) http://pages.hotbot.com/edu/eremin You can use this applet source and change it free, but You must conserve this lines about the author! Add information about Your changes after these lines! Please, send URL of Your page with applet to my E-mail eremin@hotbot.com */ /* This applet draws the computer and shows the appearance of the specified text string on its display. Typing text can be selected from the list; the animation can be paused. */ import java.applet.*; import java.awt.*; public class welcome extends java.applet.Applet implements Runnable{ String displayText="Welcome!"; String movie=""; Thread engine = null; int timeCounter=0; boolean animate=true; int x0=7; int y0=5; int Lmon=80; int Hmon=60; int Hsys=20; Button pauseButton = new Button("Pause"); Choice texts = new Choice(); //Initialize the applet public void init() { setLayout(null); setBackground(Color.yellow); add(pauseButton); pauseButton.reshape(140,10,50,25); add(texts); texts.reshape(110,60,105,10); texts.setFont(new Font("Arial",Font.BOLD,12)); texts.addItem("Welcome!"); texts.addItem("Be happy!"); texts.addItem("Have fun!"); texts.addItem("Nice Java."); texts.addItem("E.A.Eremin"); texts.select(0); //===== Tread that makes animation ===== //create tread engine = new Thread(this); engine.start(); engine.suspend(); //pause in thread (see start after) } public void start(){ engine.resume(); //restart thread } public void run(){ //work of the thread - animation engine while (true) { //add current letter or wait if (animate) timeCounter++; else timeCounter=3*displayText.length()-1; //no animation if (timeCounter<=displayText.length()) movie=displayText.substring(0,timeCounter); repaint(); //show picture changes if (timeCounter>=3*displayText.length()) timeCounter=-1; //repeat again //delay try {engine.sleep(250);} catch(InterruptedException e) {} } } public void stop(){ engine.suspend(); //pause the thread } public void destroy(){ if (engine != null) {engine.stop(); engine = null;} } //Get Applet information public String getAppletInfo() { return "E.A.Eremin: Welcome Applet"; } public void update(Graphics g){ if (animate) g.setColor(Color.green); //green indicator else g.setColor(Color.red); //red indicator g.fillRect(x0+7,y0+Hmon+9,4,2); if ( (!animate) | (timeCounter>displayText.length()) ) return; //no animation and "all text is on screen" pause //===== Screen text ===== if (timeCounter==0) {g.setColor(Color.cyan); g.fillRect(x0+5,y0+5,Lmon-9,Hmon-11); } //clear screen else {g.setColor(Color.black); g.setFont(new Font("Arial",Font.BOLD,12)); g.drawString(movie,x0+10,y0+32); } //write text string } public void drawComp(Graphics g){ // ===== system unit ===== //system: front g.setColor(Color.lightGray); g.fillRect(x0,y0+Hmon+3,Lmon,Hsys); g.setColor(Color.black); g.drawRect(x0,y0+Hmon+3,Lmon,Hsys); //shaddow g.setColor(Color.white); g.drawLine(x0+1,y0+Hmon+4,x0+Lmon-1,y0+Hmon+4); g.drawLine(x0+1,y0+Hmon+4,x0+1,y0+Hmon+Hsys+2); //indicator g.setColor(Color.black); g.drawRect(x0+6,y0+Hmon+8,5,3); g.setColor(Color.green); //green indicator g.fillRect(x0+7,y0+Hmon+9,4,2); //2 floppy int xl=x0+Lmon-25; int y1=y0+Hmon+9; for (int k=1; k<3; k++) {g.setColor(Color.darkGray); g.fillRect(xl,y1,21,4); g.setColor(Color.white); g.fillRect(xl,y1,20,3); y1+=6;} //system: sides g.setColor(Color.black); g.drawLine(x0+Lmon+1,y0+Hmon+Hsys+3,x0+Lmon+10,y0+Hmon+Hsys-6); g.drawLine(x0,y0+Hmon+3,x0+9,y0+Hmon-6); g.drawLine(x0+Lmon+11,y0+Hmon-5,x0+Lmon+11,y0+Hmon+Hsys-7); g.setColor(Color.white); g.drawLine(x0+Lmon+1,y0+Hmon+3,x0+Lmon+10,y0+Hmon-6); //system: top g.setColor(Color.darkGray); for (int i2=1; i2<11; i2++) g.drawLine(x0+1+i2,y0+Hmon+3-i2,x0+Lmon+i2,y0+Hmon+3-i2); //system: right g.setColor(Color.darkGray); for (int i3=1; i3<11; i3++) g.drawLine(x0+Lmon+i3,y0+Hmon+5-i3,x0+Lmon+i3,y0+Hmon+Hsys+3-i3); // ===== monitor ===== //monitor: front g.setColor(Color.lightGray); g.fillRect(x0,y0,Lmon,Hmon); g.setColor(Color.black); g.drawRect(x0,y0,Lmon,Hmon); //shaddow g.setColor(Color.white); g.drawLine(x0+1,y0+1,x0+Lmon-1,y0+1); g.drawLine(x0+1,y0+1,x0+1,y0+Hmon-1); //monitor: screen g.setColor(Color.black); g.drawRect(x0+4,y0+4,Lmon-8,Hmon-10); g.setColor(Color.cyan); g.fillRect(x0+5,y0+5,Lmon-9,Hmon-11); //shaddow g.setColor(Color.white); g.drawLine(x0+Lmon-3,y0+4,x0+Lmon-3,y0+Hmon-5); g.drawLine(x0+4,y0+Hmon-5,x0+Lmon-4,y0+Hmon-5); //monitor: sides g.setColor(Color.black); g.drawLine(x0+Lmon+1,y0,x0+Lmon+10,y0+9); g.drawLine(x0+Lmon+1,y0+Hmon,x0+Lmon+10,y0+Hmon-9); g.drawLine(x0+Lmon+10,y0+9,x0+Lmon+10,y0+Hmon-9); g.setColor(Color.darkGray); for (int i1=1; i1<10; i1++) g.drawLine(x0+Lmon+i1,y0+i1,x0+Lmon+i1,y0+Hmon-i1); } public void paint(Graphics g){ int h=size().height; int w=size().width; g.setColor(Color.red); g.drawRect(0,0,w-1,h-1); g.drawRect(1,1,w-3,h-3); //frame //separate button int xb=105; g.drawLine(xb,0,xb,h); g.drawLine(xb+1,0,xb+1,h); g.setColor(Color.blue); g.setFont(new Font("Arial",Font.BOLD,12)); g.drawString("Select text:",110,55); drawComp(g); update(g); showStatus("Welcome to my homepage!"); } //Controls public boolean action(Event e, Object o) { if (e.target instanceof Button) animate=!animate; //change to opposite if (e.target instanceof Choice) {displayText=texts.getSelectedItem(); timeCounter=-1; //start new string from the beginning } return(true); } }