?? hushapplet.java
字號:
/* * File: HushApplet.java * * Version 1.02 v1a * Copyright 1998, 1999 by Hush Communications Corporation, BWI *//* * Applet parameters: * * username = < the users HushMail account > * sessionID = < a 64 bit hex number represented as a string > * sessionKey = < a 128 bit hex number represented as a string > * R0 = < red value for applet color > * G0 = < green value for applet color > * B0 = < blue value for applet color > * R1 = < red value for applet color > * G1 = < green value for applet color > * B1 = < blue value for applet color > * clicksPerAdRotation = * <number of button click between each ad rotation> * keyStrokesPerAdRotation = * <number of key strokes between each ad rotation> * exitpage = < the url to the script that handles exits > * (optional) smallApplet = < if "yes" applet dimesions are assumed to be 600X350 > *//* Unless otherwise indicated applet dimensions are assumed to be 720X370 */package hushcode;import java.applet.*;import java.awt.*;import java.net.*;import java.util.*;import java.io.*;import hushcode.Connection;import hushcode.BlinkingText;public class HushApplet extends Applet { public void init() { /* Get applet color and size */ color = new Color(Integer.parseInt(getParameter("R1")), Integer.parseInt(getParameter("G1")), Integer.parseInt(getParameter("B1"))); bgcolor = new Color(Integer.parseInt(getParameter("R0")), Integer.parseInt(getParameter("G0")), Integer.parseInt(getParameter("B0"))); exitpage = getParameter("exitpage"); if (getParameter("small").equals("yes")) smallApplet=true; /* Set the lines per page and maximum string length for * folder, message, address lists based on applet size */ if (smallApplet) { linesPerPage = 9; maxMessageInfoLength = 165; maxFolderInfoLength = 200; maxAddressInfoLength = 110; } else { linesPerPage = 10; maxMessageInfoLength = 165; maxFolderInfoLength = 325; maxAddressInfoLength = 170; } /* Set rotation rate for ads */ if (getParameter("keyStrokesPerAdRotation")!=null) { keyStrokesPerAdRotation = Integer.parseInt(getParameter("keyStrokesPerAdRotation")); if (getParameter("clicksPerAdRotation")!=null) clicksPerAdRotation = Integer.parseInt(getParameter("clicksPerAdRotation")); } /* Format the applet and set it up with a LayoutManager */ setBackground(bgcolor); setForeground(Color.white); setFont(new Font("Helvetica",Font.PLAIN,12)); currentScreen = "login"; appletLayout=new GridBagLayout(); appletConstraints=new GridBagConstraints(); setLayout(appletLayout); /* Set up the passphrase fields */ passphraseLabel=new Label("Enter passphrase:"); passphraseLabel.setFont(new Font("Helvetica",Font.PLAIN,12)); add(this,appletConstraints,passphraseLabel,0,0,1,1,0,0,1,1,NO,NE,20,0,0,0); passphraseField=new TextField(50); passphraseField.setBackground(Color.white); passphraseField.setForeground(Color.black); passphraseField.setEchoCharacter('*'); add(this,appletConstraints,passphraseField,1,0,1,1,0,0,0,1,NO,N,20,0,0,10); formatButton3(passphraseButton = new Button("Go")); add(this,appletConstraints,passphraseButton,2,0,1,1,0,0,1,1,NO,NW,20,0,0,0); /* Instantiate the class for communication with server. * See "Connection.java" for methods called on this object. */ c = new Connection(getParameter("username"),getParameter("sessionID"),getParameter("sessionKey"),this); /* After login, the applet has four main panels * 1) Menu * 2) Commands * 3) Main * 4) StatusBar */ setUpCommands(); setUpMain(); /* set up Status Bar */ statusBar = new Panel(); statusBar.setLayout(new GridBagLayout()); statusBar.setBackground(color); statusBar.setForeground(Color.black); statusBar.paintAll(statusBar.getGraphics()); } public void init2() { /** * This method is called after the passphrase has been entered. It submits * the passphrase and username for approval. * It completes the setup of the various applet screens and retireves a list * of folders, addresses, and the messages in the inbox. It displays * a list of the messages in the inbox. */ /* Add the panels to the applet * The "menu" panel is conceptual only, as it uses the applet itself as a background */ statusBar("Session started"); add(this,appletConstraints,commands,1,0,1,1,0,10,0,0,B,NW,0,120,0,0); add(this,appletConstraints,main,1,1,1,1,0,0,1,1,B,NW,0,120,0,0); add(this,appletConstraints,statusBar,1,2,1,1,0,statusBar.bounds().height,0,0,B,NW,0,120,0,0); c.setPassphrase(passphraseField.getText()); passphraseField.setText(""); try { if (c.use()) { listMessages("inbox",0,true); listFolders(0,true); listAddresses(0,true); if (c.numberOfMessages()>0) add(commands,commandsConstraints,selectAllButton,0,0,1,1,0,0,0,0,NO,W,3,6,3,0); c.done(); remove(passphraseLabel); remove(passphraseField); remove(passphraseButton); /* Show the inbox first */ currentScreen = "listMessages"; mainLayout.show(main,currentScreen); paintAll(getGraphics()); } } catch (IOException e) { c.quit(); String docBase = getDocumentBase().toString(); try { URL u = new URL(exitpage+"?action=Error&username="+c.username()); getAppletContext().showDocument(u); c.wipeMessage(); c.killPassCipher(); removeAll(); paintAll(getGraphics()); } catch (MalformedURLException mue) {System.out.println("Malformed URL");} stop(); } } public void paint(Graphics g) { /** * Method to override Applet.paint(); */ statusBar.removeAll(); Label fillerLabel = new Label("Applet redrawn"); fillerLabel.setForeground(color); statusBar.add(fillerLabel); statusBar.paintAll(statusBar.getGraphics()); paintComponents(g); /* At the start, give focus to the passphrase field */ if (currentScreen.equals("login")) { passphraseField.requestFocus(); } /* Draw the menu buttons on the applet left side */ else { try {/*********************************************************************************** * The "menu" panel * This panel is on the far left side of the applet * It consists of five buttons which perform major actions * This panel is never altered after it is set up. * It isn't actually a seperate panel, but for conceptual purposes * I consider it to be. ***********************************************************************************/ URL u = new URL(getDocumentBase().getProtocol(),getDocumentBase().getHost(),"/images/"); g.drawImage(getImage(new URL(u,"button0.gif")),43,20,this); g.drawImage(getImage(new URL(u,"check.gif")),13,50,this); g.drawImage(getImage(new URL(u,"button0.gif")),43,85,this); g.drawImage(getImage(new URL(u,"folders.gif")),24,115,this); g.drawImage(getImage(new URL(u,"button0.gif")),43,150,this); g.drawImage(getImage(new URL(u,"compose.gif")),23,180,this); g.drawImage(getImage(new URL(u,"button0.gif")),43,215,this); g.drawImage(getImage(new URL(u,"addresses.gif")),17,245,this); g.drawImage(getImage(new URL(u,"button0.gif")),43,280,this); g.drawImage(getImage(new URL(u,"quit.gif")),38,310,this); } catch (MalformedURLException e) {System.out.println("MalformedURL");} } } public void update(Graphics g) { /** * Method to override Applet.update(); */ paint(g); } /*********************************************************************************** * Event Handling ***********************************************************************************/ public boolean mouseMove(Event e, int x, int y) { if (currentScreen.equals("login")) return true; else if (y>=20 && y<=45 && x>=43 && x<=67) { getAppletContext().showStatus("Check mail"); } else if (y>=85 && y<=110 && x>=43 && x<=67) { getAppletContext().showStatus("Folders"); } else if (y>=150 && y<=175 && x>=43 && x<=67) { getAppletContext().showStatus("Compose"); } else if (y>=215 && y<=240 && x>=43 && x<=67) { getAppletContext().showStatus("Addresses"); } else if (y>=280 && y<=305 && x>=43 && x<=67) { getAppletContext().showStatus("Quit"); } else getAppletContext().showStatus(""); return true; } private boolean bc(int x, int y, Component c) { int t = c.bounds().y; int b = t + c.bounds().height; int l = c.bounds().x; int r = l + c.bounds().width; if (x>l&&x<r&&y>t&&y<b) return true; else return false; } private boolean lockMenu = false; public boolean mouseUp(Event e, int x, int y) { /** * Overrides Applet.mouseUp * Handle clicks over the graphics on the main menu */ /* Update rotateCount for ad changes */ rotateCount=rotateCount+(keyStrokesPerAdRotation/clicksPerAdRotation); if (currentScreen.equals("login")) return true; /* Clear status bar */ statusBar.removeAll(); /* On click of the "Check Mail" button */ if (y>=20 && y<=45 && x>=43 && x<=67 && !lockMenu) { lockButtons(true); if (currentScreen.equals("read")) c.wipeMessage(); clearCommands(); add(commands,commandsConstraints, new Label("Retrieving folder info "+ " "),0,0); commands.paintAll(commands.getGraphics()); try { c.use(); // The messages in the inbox are listed listMessages("inbox",0,true); // The folder list is updated to reflect changes in the number of // messages in the inbox listFolders(currentFolderPage,true); c.done(); } catch (IOException e0) {error();} currentScreen = "listMessages"; mainLayout.show(main,currentScreen); clearCommands(); if (c.numberOfMessages()>0) { add(commands,commandsConstraints,selectAllButton,0,0); showSelectFunctionButtons(messagesSelected()>0,1); commands.paintAll(commands.getGraphics()); } lockButtons(false); } /* On click of the "Folders" button */ else if (y>=85 && y<=110 && x>=43 && x<=67 && !currentScreen.equals("listFolders") && !lockMenu) { if (currentScreen.equals("read")) c.wipeMessage(); clearCommands(); add(commands,commandsConstraints,newFolderButton,0,0); add(commands,commandsConstraints,selectAllButton,1,0); currentScreen = "listFolders"; showSelectFunctionButtons(foldersSelected()>0,2); mainLayout.show(main,currentScreen); commands.paintAll(commands.getGraphics()); } /* On click of the "Compose" button */ else if (y>=150 && y<=175 && x>=43 && x<=67 && !currentScreen.equals("compose") && !lockMenu) { if (currentScreen.equals("read")) c.wipeMessage(); clearCommands();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -