?? quoter.java
字號:
/* Quoter.java * * Raven * raven@ravenmatrix.com * http://www.ravenmatrix.com * * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details at http://www.gnu.org */import java.applet.*;import java.awt.*;import java.util.*;import java.io.*;import java.net.*;public class Quoter extends java.applet.Applet {int fontSize; String fontType; String quote = "";String line[] = new String[40]; String qtext = "quotes.txt"; int l = 0; Color fontColor, backGroundColor; public void paint(Graphics g) { int x = 0, y = 0; int aWidth = 5, aHeight = 5; Font a = new Font(fontType, Font.PLAIN, fontSize); Dimension h = getSize(); Insets in = getInsets(); aWidth = (h.width - in.right - in.left); aHeight = (h.height - in.top - in.bottom); g.setColor(backGroundColor); g.fillRect(0, 0, getSize().width, getSize().height); g.setFont(a); g.setColor(fontColor); FontMetrics fm = g.getFontMetrics(); QuoteOrganizer(g, aWidth, aHeight); a = new Font(fontType, Font.PLAIN, fontSize); g.setFont(a); fm = g.getFontMetrics(); QuoteOrganizer(g, aWidth, aHeight); y = (aHeight - (l * fm.getHeight())) / 2 + (fm.getHeight() / 2); for(int z = 0; z <= l; z++ ) {g.drawString(line[z], x, y); y += a.getSize(); } } public void init () { color(); bgColor(); font(); try {URL urlQuotes = new URL(getCodeBase() + qtext); int lineNumber = 0; String line = "";InputStreamReader qr = new InputStreamReader(urlQuotes.openStream());BufferedReader qrbuffer = new BufferedReader(qr);if(qrbuffer.ready())line = qrbuffer.readLine();else {boolean readFile = false;while(readFile == false) {int j = 0;if(qrbuffer.ready()) {line = qrbuffer.readLine();readFile = true; }else {j++;}if(j == 100)readFile = true;}}int QuoteTotal = Integer.parseInt(line.trim());int quoteNumber = (int)((Math.random() * 10000000 % QuoteTotal)) + 1; while((line = qrbuffer.readLine()) != null) { lineNumber++;if(lineNumber == quoteNumber) {qrbuffer.close();quote = line.substring(0, line.indexOf("||"));qrbuffer.close();qr.close();return; }}qrbuffer.close();qr.close();}catch(IOException e) {System.exit(1); } } public void QuoteOrganizer(Graphics g, int bWidth,int bHeight) { String SingleLine = ""; String word = ""; FontMetrics fm = g.getFontMetrics(); int space = fm.stringWidth(" "); l = 0; for(StringTokenizer t = new StringTokenizer(quote); t.hasMoreTokens();) { word = t.nextToken(); int w = fm.stringWidth(word) + space; int lw = fm.stringWidth(SingleLine); if(t.hasMoreTokens()) {if(lw + w > (bWidth - 10)) { line[l] = SingleLine; l++; SingleLine = word + " "; }else{SingleLine += " " + word; }} else{ if(lw + w > (bWidth - 10)) { line[l] = SingleLine; l++; line[l] = word + ""; } else{ SingleLine = SingleLine + " " + word; line[l] = SingleLine;}}}} public void font() { String fontList[];String font; int i; if(getParameter("fontSize") != null) {fontSize = Integer.parseInt(getParameter("fontSize"));}else{fontSize = 14;}font = getParameter("font"); if(font == null){fontType ="TimesRoman";}else{fontList = getToolkit().getFontList(); for(i = 0; i < fontList.length; i++){ if(font.equalsIgnoreCase(fontList[i])){fontType = fontList[i];break;}}if(i == fontList.length);{fontType = "TimesRoman";}} } public void bgColor() { String color = getParameter("bgcolor"); if(color == null || color.equalsIgnoreCase("white")){backGroundColor = Color.white;}else if(color.equalsIgnoreCase("black")){backGroundColor = Color.black;} else if(color.equalsIgnoreCase("lightGray")){backGroundColor = Color.lightGray;}else if(color.equalsIgnoreCase("gray")){backGroundColor = Color.gray;} else if(color.equalsIgnoreCase("darkGray")){backGroundColor = Color.darkGray;}else if(color.equalsIgnoreCase("red")){backGroundColor = Color.red;}else if(color.equalsIgnoreCase("pink")){backGroundColor = Color.pink;}else if(color.equalsIgnoreCase("orange")){backGroundColor = Color.orange;}else if(color.equalsIgnoreCase("yellow")){backGroundColor = Color.yellow;} else if(color.equalsIgnoreCase("green")){backGroundColor = Color.green;} else if(color.equalsIgnoreCase("magenta")){backGroundColor = Color.magenta;} else if(color.equalsIgnoreCase("cyan")){backGroundColor = Color.cyan;}else if(color.equalsIgnoreCase("blue")){backGroundColor = Color.blue;}else{backGroundColor = Color.white;} } public void color(){ String color = getParameter("color"); if(color == null || color.equalsIgnoreCase("black")) { fontColor = Color.black;}else if(color.equalsIgnoreCase("white")){fontColor = Color.white;} else if(color.equalsIgnoreCase("lightGray")){fontColor = Color.lightGray;}else if(color.equalsIgnoreCase("gray")){fontColor = Color.gray;} else if(color.equalsIgnoreCase("darkGray")){ fontColor = Color.darkGray;}else if(color.equalsIgnoreCase("red")){fontColor = Color.red;}else if(color.equalsIgnoreCase("pink")){fontColor = Color.pink;}else if(color.equalsIgnoreCase("orange")){fontColor = Color.orange;}else if(color.equalsIgnoreCase("yellow")){fontColor = Color.yellow;} else if(color.equalsIgnoreCase("green")){ fontColor = Color.green;} else if(color.equalsIgnoreCase("magenta")){fontColor = Color.magenta;} else if(color.equalsIgnoreCase("cyan")){fontColor = Color.cyan;}else if(color.equalsIgnoreCase("blue")){fontColor = Color.blue;}else{ fontColor = Color.black;} } public static void main (){Quoter quotes = new Quoter();}}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -