±Û¾´ÀÌ :Á¶½ÅÁ¦ 1999³â 4¿ù 22ÀÏ 11:05:41
In Reply to: ¾ÖÇø´¿¡¼ ÇÁ¸°Æ® ÇÏ´Â ¿¹Á¦Á» ºÎŹµå¸³´Ï´Ù. posted by ÀÓ°æÀç on 1999³â 4¿ù 22ÀÏ 07:05:22:
¾Æ·¡ÀÇ ¿¹Á¦´Â [JAVA EXAMPLES IN A NUTSHELL] ¿¡ ÀÖ´Â ¾îÇø®ÄÉÀ̼ÇÀ»
ÇÁ¸°ÅÍÇÏ´Â ¿¹Á¦¸¦ ¾ÖÇø´¿¡¼ ÇÁ¸°Æ®ÇÒ ¼ö ÀÖ°Ô Á¦°¡ ¹Ù²Ù¾î ºÃ½À´Ï´Ù¸¸,
ÀÌ ¾ÖÇø´À» Sign ÇÏÁö ¾Ê°í ÇÁ¸°Æ®¸¦ ÇÏ·Á ÇÏ¸é ³Ý½ºÄÉÀÌÇÁÀÇ ÀÚ¹ÙÄֿܼ¡
¾Æ·¡¿Í °°Àº ¿¹¿Ü ¸Þ½ÃÁö°¡ ¶ß°Ô µË´Ï´Ù.
============ ÇÁ·Î±×·¥ ¼Ò½º ========================
// This example is from _Java Examples in a Nutshell_. (http://www.oreilly.com)
// Copyright (c) 1997 by David Flanagan
// This example is provided WITHOUT ANY WARRANTY either expressed or implied.
// You may study, use, modify, and distribute it for non-commercial purposes.
// For any commercial use, see http://www.davidflanagan.com/javaexamples
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.applet.*;
/** An application that can print the user's scribbles */
public class PrintScribble extends Applet {
private short last_x = 0, last_y = 0; // last click posistion
private Vector lines = new Vector(256,256); // store the scribble
private Properties printprefs = new Properties(); // store user preferences
private Frame _appletFrame = null;
public void init() {
_appletFrame = (Frame)getParent();
// Add a print button.
this.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
Button b = new Button("Print");
this.add(b);
// Call the print() method when the button is clicked.
// Note anonymous class.
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { print(); }
});
// Register other event types we're interested in -- for scribbling
enableEvents(AWTEvent.MOUSE_EVENT_MASK |
AWTEvent.MOUSE_MOTION_EVENT_MASK);
}
/** Redraw (or print) the scribble based on stored lines */
public void paint(Graphics g)
{
for(int i = 0; i < lines.size(); i++) {
Line l = (Line)lines.elementAt(i);
g.drawLine(l.x1, l.y1, l.x2, l.y2);
}
}
/** Print out the scribble */
void print() {
// Obtain a PrintJob and a Graphics object to use with it
Toolkit toolkit = _appletFrame.getToolkit();
PrintJob job = toolkit.getPrintJob(_appletFrame, "PrintScribble", printprefs);
if (job == null) return; // If the user clicked Cancel in the print dialog
Graphics g = job.getGraphics();
// Give the output a larger top and left margin. Otherwise it will
// be scrunched up in the upper-left corner of the page.
g.translate(100, 100);
// Draw a border around the output area.
Dimension size = this.getSize();
g.drawRect(-1, -1, size.width+1, size.height+1);
// Set a clipping region so our scribbles don't go outside the border
// On-screen this happens automatically, but not on paper.
g.setClip(0, 0, size.width, size.height);
// Print this component and all components it contains
this.printAll(g); // Use print() if you don't want the button to show
// Finish up.
g.dispose(); // End the page
job.end(); // End the job
}
/** Called when the user clicks */
public void processMouseEvent(MouseEvent e)
{
if (e.getID() == MouseEvent.MOUSE_PRESSED) {
last_x = (short)e.getX(); // remember click position
last_y = (short)e.getY();
}
else super.processMouseEvent(e);
}
/** Called when the the user drags the mouse: does the scribbling */
public void processMouseMotionEvent(MouseEvent e)
{
if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
Graphics g = getGraphics();
g.drawLine(last_x, last_y, e.getX(), e.getY()); // draw the line
lines.addElement(new Line(last_x, last_y, // and save the line
(short) e.getX(), (short)e.getY()));
last_x = (short) e.getX(); last_y = (short) e.getY();
}
else super.processMouseMotionEvent(e);
}
/** This nested toplevel helper class stores the coordinates
* of one line of the scribble. */
class Line {
public short x1, y1, x2, y2;
public Line(short x1, short y1, short x2, short y2) {
this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
}
}
}
============== ¿¹¿Ü ¸Þ½ÃÁö =======================
netscape.security.AppletSecurityException: security.checkgetprintjob
at java.lang.Throwable.<init>(Compiled Code)
at java.lang.Exception.<init>(Compiled Code)
at java.lang.RuntimeException.<init>(Compiled Code)
at java.lang.SecurityException.<init>(Compiled Code)
at netscape.security.AppletSecurityException.<init>(Compiled Code)
at netscape.security.AppletSecurityException.<init>(Compiled Code)
at netscape.security.AppletSecurity.checkPrintJobAccess(Compiled Code)
at sun.awt.windows.WToolkit.getPrintJob(Compiled Code)
at PrintScribble.print(Compiled Code)
at PrintScribble$1.actionPerformed(Compiled Code)
at java.awt.Button.processActionEvent(Compiled Code)
at java.awt.Button.processEvent(Compiled Code)
at java.awt.Component.dispatchEventImpl(Compiled Code)
* at java.awt.Component.dispatchEvent(Compiled Code)
at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled Code)
at java.awt.EventDispatchThread.run(Compiled Code)
at netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled Code)
À§ÀÇ ¸Þ½ÃÁö¿¡¼ º¸½ÃµíÀÌ AppletSecurityExceptionÀÌ ¹ß»ýµÇ±â ¶§¹®¿¡ ÇÁ¸°Æ®°¡ ºÒ°¡´ÉÇÕ´Ï´Ù.
¸¹Àº µµ¿òÀÌ µÇ¾úÀ¸¸é ÁÁ°Ú±º¿ä.