[´äº¯]ÇÁ¸°Æ® ÄÚµå´Â Á¦°¡ À߸ø ¿Ã·È°í¿ä........


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

±Û¾´ÀÌ :Á¶½ÅÁ¦ 1998³â 7¿ù 25ÀÏ 22:18:59

In Reply to: [¿¡·¯] ¸Þ½ÃÁö°¡ ³ª´Âµ¥¿ä Çѹø¸¸ ´õ ºÎŹµå¸³´Ï´Ù. posted by ÃÖÁ¾Ã¶ on 1998³â 7¿ù 25ÀÏ 21:13:36:

ÇÁ¸°Æ® ÇÁ·Î±×·¥Àº Á¦°¡ Àß ¸ø ¿Ã·Á¼­ ´Ù½Ã ¿Ã¸³´Ï´Ù.


import java.awt.*;
import java.awt.event.*;
import java.util.*;



public class PrintExample extends Frame {
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



public PrintExample() {
super("PrintExample");



// 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(); }
});



// Exit when the user closes the window.
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { System.exit(0); }
});



// Register other event types we're interested in -- for scribbling
enableEvents(AWTEvent.MOUSE_EVENT_MASK |
AWTEvent.MOUSE_MOTION_EVENT_MASK);



// Set our initial size and pop the window up.
this.setSize(400, 400);
this.show();
}



/** 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 = this.getToolkit();
PrintJob job = toolkit.getPrintJob(this, "PrintExample", 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);
}



/** The main method. Create a PrintScribble() object and away we go! */
public static void main(String[] args)
{
PrintExample s = new PrintExample();
}



/** 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;
}
}
}



CardLayout ÇÁ·Î±×·¥Àº Á¦°¡ Á¶±Ý ¼ÕÀ» ºÃ½À´Ï´Ù.


°íÄ£ ºÎºÐÀº Ç¥½Ã¸¦ ÇØ ³õ¾Ò¾î¿ä..


import java.awt.* ;
import java.awt.event.* ;



public class CL extends java.applet.Applet
implements ActionListener {



CardLayout cl = new CardLayout();
Panel p, p1, p2, cards ;



public void init() {



setLayout(new BorderLayout()) ;
cards = new Panel() ;
p = new Panel();



add("North", p) ;
add("Center", cards) ;



//p = new Panel() ; <-- ÀÌ ºÎºÐ ¶§¹®¿¡ À̺¥Æ® ó¸®ÇÏ´Â ¹öÆ°ÀÌ Ãâ·ÂµÇÁö ¾Ê¾Ò½À´Ï´Ù.
p.add(new Label("Select Panel !!")) ;
Button button1 = new Button("Btn1");
button1.addActionListener(this); // listener¿¡ µî·ÏÀ» ÇØ¾ß À̺¥Æ®¸¦ ó¸®ÇÒ ¼ö°¡ ÀÖÁÒ.
Button button2 = new Button("Btn2");
button2.addActionListener(this); // À§¿Í ¸¶Âù°¡Áö..
p.add(button1) ;
p.add(button2) ;



// cards.setLayout(new CardLayout()) ; <-- »õ·Ó°Ô CardLayoutÀ» ¸¸µé¸é ¾ÈµÇÁÒ..
cards.setLayout(cl) ;



p1 = new Panel() ;
p1.setLayout(new GridLayout(2,2,10,10)) ;
p1.add(new Button("Label 1")) ;
p1.add(new Button("Label 2")) ;
p1.add(new Button("Label 3")) ;
p1.add(new Button("Label 4")) ;
cards.add("P1", p1) ;



p2 = new Panel() ;
p2.setLayout(new GridLayout(4,1,10,10)) ;
p2.add(new Button("Label 1")) ;
p2.add(new Button("Label 2")) ;
p2.add(new Button("Label 3")) ;
p2.add(new Button("Label 4")) ;
cards.add("P2", p2) ;

} // init



public void actionPerformed (ActionEvent e) {
if (e.getSource() instanceof Button) {
String label = ((Button)e.getSource()).getLabel() ;
if (label == "Btn1") { cl.show(cards, "P1") ; }
if (label == "Btn2") { cl.show(cards, "P2") ; }
} // instanceof Button
} // actionPerformed



} // top


¼ö°í Çϼ¼¿ä...





´ÙÀ½ ±Ûµé:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]