±è»ó¿íÀÇ db ÀÌ¿ëÇÑ awt ±×·¡ÇÁ Ãâ·Â°­ÁÂ

 

¡Ø °­Á¿¡ ´ëÇÑ Áú¹®Àº '¹®ÀÇ°Ô½ÃÆÇ'¿¡¼­ ÇØÁÖ¼¼¿ä.

°­Á¿¹Á¤ÀÔ´Ï´Ù.

¾È³çÇϼ¼¿ä. ¿À·£¸¸¿¡ °­Á¸¦ Ãß°¡Çϴ±º¿ä. ³Ñ ¿À·£¸¸ÀÌ¶ó ¾¦½º...(/^.^)_

ÀÚ ¿À´ÃÀº ¾ÖÇø´À¸·Î Canvas¿Í Scrollbar¸¦ ÀÌ¿ëÇÑ Ã­Æ®Ç¥½Ã¿¡ ´ëÇÑ °­Á¸¦ Çغ¸°Ú½À´Ï´Ù. ¸ÕÀú ÇÑ ¹ø º¸½ÃÁÒ.

Ŭ¸¯~~!! (1) Ŭ¸¯~~! (2)

Çϼ̾î¿ä? À½. °£´ÜÇÏÁö¸¸ Ãʺ¸´ÔµéÀÌ ±¸ÇöÇϽñâ´Â Á¦¹ý ±î´Ù·Î¿î Á¡ÀÌ ¸¹½À´Ï´Ù. ÀÚ¼¼È÷ »ìÆ캸½Ã¸é, ½ºÅ©·Ñ À̵¿¿¡ µû¶ó maximun°ú minimum°ªÀ» üũÇÏ¿© ±× ¿µ¿ª¸¸ Ç¥½ÃÇÏ´Â µî Èï¹Ì·Î¿î ±â´ÉÀÌ ¸¹½À´Ï´Ù.

À̹ø Â÷Æ®´Â º¸½Ã´Ù½ÃÇÇ db¸¦ ÀÌ¿ëÇÏ´Â ºÎºÐÀº ÀÏ´Ü Á¦¿ÜÇÏ°í, ´Ü¼øÈ÷ param°ªÀ¸·Î ÁÙÁÙÁÙ µ¥ÀÌŸ¸¦ ¹Þ¾Æµé¿© StringTokenizer·Î Àß¶ó¼­ Vector¿¡ ÀúÀåÇÑ ´ÙÀ½ À̵éÀ» °¢°¢ ¸ÅÄ¡½ÃÄÑ Canvas·Î ±×·È½À´Ï´Ù. ÇϳªÇϳª °øºÎÇغ¾½Ã´Ù. (ÀÌ °­Á¸¦ À§ÇØ Àú 6½Ã°£ ÄÚµùÇß½À´Ï´Ù. ¤Ì.¤Ì)

º¸½Ã´Ù½ÃÇÇ ÀÌ °ÍÀº ¾ÖÇø´ÀÔ´Ï´Ù. ±×·³ ¿ì¼± ¾ÖÇø´ Ŭ·¡½º°¡ ÀÖ¾î¾ß°ÚÁö¿ä?

ÇÑ ¹ø ¼Ò½º¸¦ º¸°Ú½À´Ï´Ù.

import java.applet.Applet;
import java.awt.*;
import java.util.*;

public class Chart extends Applet
{
String strYear, strMonth, strType, strParam1, strParam2, strUnit;
Vector vtDay, vtSent, vtRecv;
AxisCanvas axisCanvas;
ChartCanvas chartCanvas;
ScrollPanel scrollPanel;
GridBagLayout gb;
GridBagConstraints gbc;
int naxismax, naxismin;
Panel panel;

public void init()
{
setBackground(Color.white);
vtDay = new Vector(31);
vtSent = new Vector(31);
vtRecv = new Vector(31);

strParam1 = getParameter("param1");
if(strParam1 == null)
strParam1 = "";
strParam2 = getParameter("param2");
if(strParam2 == null)
strParam2 = "";
strUnit = getParameter("unit");
if(strUnit == null)
strUnit = "";
strYear = getParameter("year");
if(strYear == null)
strYear = "";
strMonth = getParameter("month");
if(strMonth == null)
strMonth = "";
strType = getParameter("type");
if(strType == null)
strType = "0";
String strtemp = getParameter("day");
if(strtemp == null)
strtemp = "";
StringTokenizer stntemp = new StringTokenizer(strtemp, ",");
for(;stntemp.hasMoreTokens();)
vtDay.addElement(stntemp.nextToken());

strtemp = getParameter("sent");
if(strtemp == null)
strtemp = "";
stntemp = new StringTokenizer(strtemp, ",");
for(;stntemp.hasMoreTokens();)
vtSent.addElement(stntemp.nextToken());

strtemp = getParameter("receive");
if(strtemp == null)
strtemp = "";
stntemp = new StringTokenizer(strtemp, ",");
for(;stntemp.hasMoreTokens();)
vtRecv.addElement(stntemp.nextToken());

gb = new GridBagLayout();
gbc = new GridBagConstraints();

panel = new Panel();
setLayout(new BorderLayout());
add("Center", panel);
panel.setLayout(gb);
gbc.ipadx = gbc.ipady = 0;

axisCanvas = new AxisCanvas(this);
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 0.1D;
gbc.weighty = 1.0D;
addComp(axisCanvas, 0, 0, 1, 1);
chartCanvas = new ChartCanvas(this);
gbc.weightx = 0.9D;
gbc.weighty = 1.0D;
addComp(chartCanvas, 1, 0, 1, 1);
scrollPanel = new ScrollPanel(this);
scrollPanel.setBackground(Color.white);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0D;
gbc.weighty = 0.005D;
addComp(scrollPanel, 1, 1, 1, 1);
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 0.1D;
gbc.weighty = 0.005D;
Panel pnX = new Panel();
pnX.setBackground(Color.white);
addComp(pnX, 0, 1, 1, 1);
}

public void addComp(Component component, int a, int b, int c, int d)
{
gbc.gridx = a;
gbc.gridy = b;
gbc.gridwidth = c;
gbc.gridheight = d;
gb.setConstraints(component, gbc);
panel.add(component);
}

public void stop()
{
}

public void destroy()
{
}
}

È÷¾ß Àý¶ó ±é´Ï´Ù. À½ ÀÌ°Å º¸´Ù ´õ ±ä ¼Ò½ºµµ Çϳª ´õ ÀÖÀ¸´Ï, ¸¶À½ÀÇ Áغñ Çϼ¼¿ä. ¿ì¼± ÂùÂùÈ÷ »ìÆ캼±î¿ä? extends AppletÇÑ °ÍÀÌ º¸À̽ÇÅ×°í, °¢Á¾ º¯¼öµéÀ» ¸â¹öº¯¼ö·Î ¼±¾ðÇß±º¿ä. ¾îµð¿¡ ¾²ÀÌ´Â º¯¼öÀÎÁö´Â ctrl+F Çؼ­ ã¾Æº¸½Ã¸é µÇ°í^_^;

AxisCanvas axisCanvas;
ChartCanvas chartCanvas;
ScrollPanel scrollPanel;

ÀÌ ¼¼ Ŭ·¡½º´Â Á¦°¡ ¸¸µç Ŭ·¡½ºÀÔ´Ï´Ù. AxisCanvas´Â Â÷Æ® ÁÂÃø¿¡ ÃàÀ» ÀÌ·ç´Â Canvas°í¿ä, ChartCanvas´Â ¸ÞÀÎ Â÷Æ®°¡ µé¾î°¡´Â Canvas°í¿ä, ScrollPanelÀº scrollbar¸¦ ³ÖÀº PanelŬ·¡½º ÀÔ´Ï´Ù.

¾ÖÇø´Àº »ý¼ºÀÚ ´ÙÀ½¿¡ ¹Ù·Î init ¸Þ¼Òµå°¡ ½ÇÇàµÇÁö¿ä? init¸Þ¼Òµå´Â ¾Æ½Ã´Ù½ÃÇÇ ¾ÖÇø´ÀÌ ·ÎµùµÉ ¶§ ´Ü ÇÑ ¹ø¸¸ ¼öÇàµÇ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù. º¸Åë ¾îÇø®ÄÉÀ̼ÇÀÇ »ý¼ºÀÚ ¿ªÇÒ(°¢Á¾ º¯¼ö ÃʱâÈ­ µî)À» ´ëü·Î ¿©±â¼­ ÇÏÁö¿ä. ±× ¾È¿¡ º¸´Ï±î... paramÀ¸·Î ¼±¾ðµÈ º¯¼öµéÀ» ¹Þ¾Æ¿À´Â ºÎºÐÀÌ ÁÖ¿í ±æ°Ô º¸À̴±º¿ä. ´Ù ¶È°°Àº ¸ð¾çÀä, null°ªÀÌ ³Ñ¾î¿À¸é StringÀ¸·Î Ç¥½ÃÇÒ ¶§ null !! ÇÏ°í Ç¥½ÃµÇ´Ï±î ¾Ö½á "" °ø¹é°ªÀ» ³Ö¾îÁÖ°í ÀÖ½À´Ï´Ù. null°ªÀÌ ³Ñ¾î¿Ã °æ¿ìÀÇ Ã³¸®´Â ²¿¿Á ÇØÁÖ¼Å¾ß ÇÕ´Ï´Ù.

¿À¿Ê day,sent, receiveºÎÅÍ ¹Ù·Î StringTokenizer¿¡ °®´Ù ³Ö´Â±º¿ä. StringTokenizer´Â ÀÌÀü¿¡ ¾´ äÆà °­Á¿¡¼­ ¹àÇûµíÀÌ ±ä StringÀ» ÀÏÁ¤ÇÑ ÆÐŶÀ¸·Î À߶󳻴 ¿ªÇÒÀ» ½±°Ô ÇØÁִ Ŭ·¡½ºÀÔ´Ï´Ù. »ç¿ë¹ýÀº new StringTokenizer(String, "±¸ºÐÀÚ"); ÀÌ·¸°Ô »ý¼ºÇؼ­ nextToken()À¸·Î ½ºÆ®¸µÀ» ¹Þ¾Æ ¾²Áö¿ä. ÆÐŶÀº ÇÑ ¹®ÀÚ°¡ µé¾î°¥ ¼öµµ ÀÖ°í µÎ ¼¼±ÛÀÚ°¡ µé¾î°¥ ¼öµµ ÀÖ½À´Ï´Ù. µÎ ¼¼ ±ÛÀÚ°¡ µé¾î°¥ °æ¿ì¿¡´Â °¢°¢À» ¸ðµÎ ÆÐŶÀ¸·Î º¸°í ±¸ºÐÇÏÁö¿ä. "#*" ÀÌ·¸°Ô ±¸ºÐÀÚ¸¦ Á¤ÀÇÇϸé, #·Îµµ *·Îµµ ±¸ºÐÇÏÁö¿ä. StringTokenizerÀÇ ¶Ç Çϳª À¯¿ëÇÑ ¸Þ¼Òµå´Â hasMoreTokensÀÔ´Ï´Ù. for¹®¿¡¼­ À¯¿ëÇÏ°Ô ¾²°í ÀÖ±º¿ä.

ºÎ¿¬ÀÌÁö¸¸, »ç½Ç ÇÑ ¹®ÀÚ·Î µÈ ±¸ºÐÀÚ·Î ÆÐŶÀ» Àß¶ó³¾ ¶§¿¡´Â StringÀÇ indexOf ¸Þ¼Òµå¸¦ ÀÌ¿ëÇؼ­ À߶󳻴 °ÍÀÌ È¿À²ÀÌ ÁÁ½À´Ï´Ù. Çѵι®ÀÚÀÏ °æ¿ì¿¡´Â ±ÍÂú´õ¶óµµ indexOf¸¦ ÀÌ¿ëÇϽñ¸¿ä. Àú¿ä? ±ÍÂú¾Æ¼­¿ä....¤Ì.¤Ì

±× ¹Ø¿¡´Â Vector¸¦ ÀÌ¿ëÇÏ°í ÀÖ±º¿ä. À§¿¡¼­ ÀÌ¹Ì new Vector(31)·Î »ý¼ºÇØ µÎ¾ú½À´Ï´Ù. ¿Ö 31À̳ı¸¿ä? ÇÑ ´ÞÀÌ 31ÀÏ À̴ϱî..¤Ì.¤Ì; ¹Ì¸® ÀÌ·¸°Ô ¼±¾ðÇصθé 2¹è¾¿, 2¹è¾¿ Vector¾È¿¡ ¹è¿­À» »õ·Î »ý¼ºÇÏ´Â ·Îµå¸¦ ÁÙÀÏ ¼ö ÀÖ°ÚÁö¿ä.

ºÎ¿¬Àε¥, ¿Ö µÎ¼¼°³¾¿ ¾È´Ã¸®°í 2¹è¾¿Áõ°¡½ÃÅ°³ª¿ä? À½, ÄÄ¿¡¼­´Â 2¹è¾¿ Áõ°¡ÇÑ´Ù´Â °³³äÀÌ »ó´çÈ÷ ºü¸¥ È¿À²ÀÌ´õ±º¿ä... ¿ÖÀÎÁö´Â Àúµµ ¸ð¸¨´Ï´Ù.....°í¼öµµ ¸ð¸¨´Ï´Ù. Çϼöµµ ¸ð¸¨´Ï´Ù. 2Áø¼ö¸¦ ÁÁ¾ÆÇؼ­ 2¹è¸¦ ÁÁ¾ÆÇÏ´Â Áöµµ ¸ð¸¨´Ï´Ù...´ÜÁö ½ÇÇè°á°úÀÔ´Ï´Ù. ¤Ì.¤Ì

Çä! ±× º¹ÀâÇÑ GridBagLayoutÀÌ ³ª¿Ô±º¿ä. À½ ¼ÖÁ÷È÷ ½Ç¹«¿¡¼­´Â °¡Àå ¸¹ÀÌ ¾¹´Ï´Ù. ±×³É °£´ÜÈ÷ BorderLayoutÀ̳ª FlowLayoutÀ¸·Î ó¸®ÇÒ ¼ö ÀÖ´Â ¿ÜÀÇ ºÎºÐ¿¡¼­´Â ´ëºÎºÐ GridBagLayoutÀ¸·Î ó¸®ÇÏÁö¿ä. º¹ÀâÇϱä ÇÏÁö¸¸, ¸¸»çÇüÅëÀ̴ϱî... »ç¿ë¹ý ÁÙÁ٠ĥ ¼ö ÀÖÀ» Á¤µµ·Î ÇÊÈ÷ ¾Ë¾ÆµÎ½Ã±¸¿ä. ¿Ü¿ì¼¼¿ä~ ÀÌ ¼Ò½º¿¡¼­´Â °¡Àå Áß¿äÇÑ gridx gridy¿Í gridwidth, gridheight¸¸ ¹Ù·Î¹Ù·Î ¾µ ¼ö ÀÖµµ·Ï addComp¶ó´Â ¸Þ¼Òµå¸¦ Çϳª ¸¸µé¾î¼­ »ç¿ëÇß½À´Ï´Ù. °®´Ù ¾²¼Åµµ µÇ°í¿ä.

À½ ·¹À̾ƿô±îÁö ´Ù ÇÏ°í ³ª´Ï AppletÀ» »ó¼ÓÇÑ Chart Ŭ·¡½º°¡ ¿Ï¼ºµÇ¾ú±º¿ä. »ÑµíÇÕ´Ï´Ù.

±× ´ÙÀ½¿¡ ³ª¿Â AxisCanvas¸¦ ÇÑ ¹ø º¼±î¿ä?

import java.awt.*;

public class AxisCanvas extends Canvas
{
int nmax, nmin;
Chart applet;

AxisCanvas(Chart applet)
{
this.applet = applet;
setBackground(Color.white);
}

public void paint(Graphics g)
{
nmax = applet.naxismax;
nmin = applet.naxismin;
FontMetrics fm = g.getFontMetrics(g.getFont());
Image backImg = createImage(getSize().width, getSize().height);
Graphics G = backImg.getGraphics();
G.setColor(Color.lightGray);
G.drawString("¡ã", getSize().width - 10 - (int)(fm.stringWidth("¡ã") / 2), 10);
//¼öÁ÷¼±
G.drawLine(getSize().width - 10, 10, getSize().width - 10, getSize().height - 20);
//¸Ç ¾Æ·¡ ¼öÆò¼±
G.drawLine(getSize().width - 10, getSize().height - 20, getSize().width, getSize().height - 20);

G.drawLine(getSize().width - 6, (int)(getSize().height / 6), getSize().width- 14, (int)(getSize().height / 6));

G.drawLine(getSize().width - 8, (int)(getSize().height / 3), getSize().width - 12, (int)(getSize().height / 3));

G.drawLine(getSize().width - 6, (int)(getSize().height * 5 / 6), getSize().width - 14, (int)(getSize().height * 5 / 6));

G.drawLine(getSize().width - 8, (int)(getSize().height * 2 / 3), getSize().width - 12, (int)(getSize().height * 2/ 3));

G.drawLine(getSize().width - 6, (int)(getSize().height / 2), getSize().width - 14, (int)(getSize().height / 2));

G.setColor(Color.black);
G.drawString(applet.strParam1,1, 15);
G.setColor(new Color(100,100,255));
G.fill3DRect(1, 23, 30, 3, true);
G.drawString(applet.strParam2, 1, 45);
G.setColor(new Color(255,100,100));
G.fill3DRect(1, 53, 30, 3, true);
G.drawString(nmax + applet.strUnit , getSize().width - fm.stringWidth(nmax + applet.strUnit) - 12, (int)(getSize().height / 6));
G.drawString(nmin + applet.strUnit, getSize().width - fm.stringWidth(nmin + applet.strUnit) - 12, (int)(getSize().height * 5 / 6));
G.drawString((int)((nmax + nmin)/ 2) + applet.strUnit, getSize().width -
fm.stringWidth((int)((nmax + nmin)/ 2) + applet.strUnit ) - 12, (int)(getSize().height / 2));

g.drawImage(backImg, 0, 0, this);
backImg.flush();
G.dispose();
//ÁöÇ¥ Ãß°¡ÇÏÀÚ.
}
}

À½, AxisCanvas´Â ¾Æ±î ¸»¾¸µå·È´ø ´ë·Î ¾ÖÇø´ÀÇ ¿ÞÂÊ¿¡ ºÙ¾î ÁÂÇ¥ÃàÀ» ³ªÅ¸³»´Â Ŭ·¡½ºÀÔ´Ï´Ù. ¹¹ ±×³É Áß¾Ó Ã­Æ®¿¡¼­ ´Ù ó¸®ÇÒ ¼öµµ ÀÖÁö¸¸,(¾Æ·¡ XÃàÀº ±×·¸°Ô ÇÏ°í ÀÖ½À´Ï´Ù.) ¹¹... ¸ÚÀÖÀݾƿä ^_^; ±×³É ÇÑ ¹ø ³ª´²ºÃ½À´Ï´Ù. °øºÎµµ µÇ½Ç°â...

È÷¾ß ÀÌ Å¬·¡½º´Â »ó´çÈ÷ º¹ÀâÇغ¸ÀÔ´Ï´Ù¸¸. °á±¹ »ý¼ºÀÚ¿Í paint¸Þ¼Òµå µÑ ¹Û¿¡ ¾ø½À´Ï´Ù. CanvasŬ·¡½º´Â paint¸Þ¼Òµå°¡ »ý¸íÀÌÁÒ. ¹¹ ´ëºÎºÐ Component°¡ paint¸¦ Áö¿øÇϱâ´Â ÇÕ´Ï´Ù¸¸...

AxisCanvas¸¦ »ý¼ºÇÒ ¶§, this·Î ¾ÖÇø´Å¬·¡½º(Chart)¸¦ ³Ñ°ÜÁá½À´Ï´Ù. À½ »ç½Ç ÀÌ·± ¹æ½ÄÀº °´Ã¼ÁöÇâÀû ±¸Á¶¿¡´Â ¹ÝÇÏ´Â ³»¿ëÀÔ´Ï´Ù¸¸, ¹¹ °£´ÜÇÑ ÇÁ·Î±×·¡¹ÖÀÌ´Ï ¾ÆÁÖ ±»~~ °ÇÇÏ°Ô ´Ü°áµÈ Ŭ·¡½º¸¦ ¸¸µé¾î ÆíÀǸ¦ µµ¸ðÇß½À´Ï´Ù. ¤Ì.¤Ì; º¯¼ö appletÀ¸·Î ¹Þ¾Æ¿ÔÁö¿ä.

±× ´ÙÀ½Àº °ñÄ¡¾ÆÇ ±×¸®±â¸¦ paint¿¡¼­ ¼öÇàÇÏ°í ÀÖ½À´Ï´Ù. ¸ÞÀÎíƮ Ŭ·¡½º¿¡¼­ maximum°ª°ú minimum°ªÀÌ ¹Ù²ð °æ¿ì repaint¸¦ ÇØÁÖ¾î °ªÀ» ¹Ù²Ù¸é¼­ ´Ù½Ã ±×¸®µµ·Ï ÇÏ°í ÀÖÁö¿ä. Graphics °´Ã¼¸¦ ÀÌ¿ëÇؼ­ drawLine, drawRect, fillRect, fill3DRect µîÀ» ±×¸®°í ÀÖ°í, ¾ù ´õºí¹öÆÛ¸µÀ» ¾²°í ÀÖ±º¿ä. (³»°¡ ÄÚµùÇÏ°í¼­ ³î¶õ ô ÇÏ°í ÀÖ±º¿ä...--a) ´õºí¹öÆÛ¸µ¿¡ ´ëÇØ Àß ¸ð¸£½Ã´Â ºÐÀÌ¶óµµ ÀÌ ÄÚµùÀ» ±×´ë·Î ¾²½Ã¸é µÇ°Ú½À´Ï´Ù. ±×¸®±â ¼º´ÉÀ» Çâ»ó½ÃÄÑ ÁÖÁö¿ä.

¹®ÀåÀÇ width³ª ³ôÀÌ µîµîÀ» ¾²±â À§Çؼ­

FontMetrics fm = g.getFontMetrics(g.getFont());

¹®ÀåÀÌ º¸À̴±º¿ä. fm°´Ã¼¿¡ stringWidth¿Í getHeight¸¦ ÀÌ¿ëÇØ À¯¿ëÇÏ°Ô ¾²°í ÀÖ½À´Ï´Ù. CanvasŬ·¡½º´Â ÁÂÇ¥¸¦ ÀÌ¿ëÇØ ±×¸² ±×¸®µíÀÌ ´Ù ÇØÁÖ¾î¾ß Çϱ⠶§¹®¿¡, ÀÌó·³ StringÀ» ±×¸± ¶§, Á¤È®ÇÑ ÁÂÇ¥ ÁöÁ¤À» À§ÇØ FontMetrics°´Ã¼°¡ ÇÊ¿äÇÏÁö¿ä. À¯¿ëÇÑ ¸Þ¼Òµå°¡ ¸¹À¸´Ï API¸¦ ÂüÁ¶ÇϽðí¿ä.

ÇÑ °¡Áö ÁÖÀÇÇÏ½Ç Á¡Àº StringÀ» ±×¸®½Ç ¶§, ±× ±âÁØ ÁÂÇ¥°¡ StringÀÇ ¿ÞÂÊ ¾Æ·¡°¡ µÈ´Ù´Â °ÍÀÔ´Ï´Ù. µû¶ó¼­, ÀÏÁ¤ ÁöÁ¡ ¾Æ·¡¿¡ StringÀ» ±×¸®°í ½ÍÀ¸¸é getHeight·Î StringÀÇ ³ôÀ̸¦ ±¸ÇÑ ´ÙÀ½ ±× ¸¸Å­ ´õÇØÁÖ½Ã¸é µÇ°Ú±¸¿ä. ¾î¶² Á¡À» ±âÁØÀ¸·Î ¿ÞÂÊ¿¡ °¡º¯±æÀÌÀÇ StringÀ» ±×¸®·Á¸é stringWidth¸Þ¼Òµå¸¦ ÀÌ¿ëÇØ StringÀÇ width¸¦ ±¸ÇÑ ´ÙÀ½ ±âÁØ Á¡¿¡¼­ »©ÁÖ½Ã¸é µÇ°ÚÁö¿ä.

naxismax¿Í naxisminÀÌ º¸À̴±º¿ä.ÃÖ´ë°ª°ú ÃÖ¼Ò°ªÀÌ°í À̸¦ ÀÌ¿ëÇØ Áß°£°ªÀ» ±¸ÇÒ ¶§ ¾¹´Ï´Ù.

applet.strUnit´Â "M"³Ä "G"³Ä chart.html¿¡¼­ paramÀ¸·Î ³Ñ°ÜÁÖ´Â °ªÀ» ¾ÖÇø´¿¡¼­ ¹Þ¾Æ¿Â °ªÀ¸·Î ±×¸® Áß¿äÇÑ °ÍÀÌ ¾Æ´Õ´Ï´Ù.

Axis´Â ±×·±´ë·Î °£´ÜÇϱº¿ä. ´ÙÀ½ Ŭ·¡½º¸¦ º¸½Ã°Ú½À´Ï´Ù.

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

public class ScrollPanel extends Panel implements AdjustmentListener
{
Chart applet;
Scrollbar scr;

ScrollPanel(Chart applet)
{
this.applet = applet;
scr = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 14);
scr.addAdjustmentListener(this);
setLayout(new BorderLayout());
add(scr, BorderLayout.CENTER);
setBackground(Color.white);
}

public void adjustmentValueChanged(AdjustmentEvent e)
{
//ó¸®
//e.getValue();
applet.chartCanvas.sbChanged(scr);

}

}

À½ ÀÌ°Å´Â ´õ ½±±º¿ä. ±×³É PanelÀ» Çϳª ¸¸µé¾î °Å±â¿¡ BorderLayoutÀ» ÀÌ¿ëÇØ scrollbar¸¦ Çϳª »ý¼ºÇØ ºÙ¿´½À´Ï´Ù. ÀÌ scrollbar¿¡´Â AdjustmentListner(this)¸¦ ºÙ¿©¾ß°ÚÁö¿ä? µû¶ó¼­ public void adjustmentValueChanged(AdjustmentEvent e)µµ ±¸ÇöÇØ ³Ö¾ú°í, ÀÌ´Â ¸ÞÀÎÂ÷Æ®ÀÇ sbChanged¸Þ¼Òµå¸¦ È£ÃâÇÕ´Ï´Ù. sbChanged¸Þ¼Òµå´Â ¸ÞÀÎÂ÷Æ®ÀÇ ±âÁØÁÂÇ¥ÃàÀ» À̵¿½ÃŲ ÈÄ(Áß¿ä!! translate¸Þ¼Òµå ÀÌ¿ë) ´Ù½Ã ±×¸®µµ·Ï ÇØÁÝ´Ï´Ù.

ÀÌÁ¦ Á¦ÀÏ Áß¿äÇÑ ¸ÞÀÎÂ÷Æ® Ŭ·¡½º ChartCanvasÀÔ´Ï´Ù.

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

public class ChartCanvas extends Canvas //implements MouseMotionListener
{
Chart applet;
private int nPrePointX, nPrePointY, nPointX, nPointY, nOriginX;
private boolean pointFlag;
private Image backImg;
private Graphics G;

ChartCanvas(Chart applet)
{
this.applet = applet;
setBackground(Color.white);
}

public void sbChanged(Scrollbar scrollbar)
{
nOriginX = -scrollbar.getValue() * 30;
repaint();
}

/*

public void mouseMoved(MouseEvent e)
{
nPointX = e.getX();
nPointY = e.getY();
// if(nPointX != nPrePointX || nPointY != nPrePointY)
// {
drawMoveXLine(nPointX);
drawMoveYLine(nPointY);
// }
nPrePointX = nPointX;
nPrePointY = nPointY;
}

public void mouseDragged(MouseEvent e)
{
nPointX = e.getX();
nPointY = e.getY();
// if(nPointX != nPrePointX || nPointY != nPrePointY)
// {
drawMoveXLine(nPointX);
drawMoveYLine(nPointY);
// }
nPrePointX = nPointX;
nPrePointY = nPointY;
}

*/

public void drawMoveXLine(int i)
{
Graphics g = getGraphics();
g.setColor(Color.black);
g.setXORMode(Color.white);
if(!pointFlag)
g.drawLine(nPrePointX, 1, nPrePointX, getSize().height - 15);
g.drawLine(i, 1, i, getSize().height - 15);
pointFlag = false;
g.dispose();
}

public void drawMoveYLine(int i)
{
Graphics g = getGraphics();
g.setColor(Color.black);
g.setXORMode(Color.white);
if(!pointFlag)
g.drawLine(1, nPrePointY, getSize().width - 1, nPrePointY);
g.drawLine(1, i, getSize().width - 1, i);
pointFlag = false;
g.dispose();
}

public void setDBuf()
{
backImg = createImage(getSize().width, getSize().height);
G = backImg.getGraphics();
}

public void setOrigin()
{
G.translate(nOriginX, 0);
}

public void setOutLine()
{
G.setColor(Color.black);
G.drawRect(1 - nOriginX, 1, getSize().width - 2, getSize().height - 30);
}

public void setGrid(FontMetrics fm)
{
G.setColor(Color.lightGray);

//¼öÆò¼±±×¸®±â
for(int i = 0; i < 6 ; i++)
G.drawLine(2-nOriginX, (int)(getSize().height * i / 6), getSize().width - 2-nOriginX, (int)(getSize().height * i / 6));

//XÃà ±×¸®±â
G.drawLine(-nOriginX, getSize().height - 20,getSize().width - 15 -nOriginX, getSize().height - 20);
G.drawString("¢º", getSize().width - 15 -nOriginX, getSize().height - 20 + (int)(fm.getHeight() / 2)- 1);

//¼öÁ÷¼±±×¸®±â
}
public void setRange()
{
applet.naxismax = applet.naxismin = 0;
for(int i=0; i < applet.vtDay.size() && i < applet.vtSent.size() && i < applet.vtRecv.size() ; i++)
{
if( i == 0 )
applet.naxismin = (Integer.parseInt((String)applet.vtSent.elementAt(i)) < Integer.parseInt((String)applet.vtRecv.elementAt(i)) ?
Integer.parseInt((String)applet.vtSent.elementAt(i)) : Integer.parseInt((String)applet.vtRecv.elementAt(i)));
if( i > (int)(-nOriginX / 30) && i < (int)((-nOriginX + getSize().width) / 30) )
{
if(Integer.parseInt((String)applet.vtSent.elementAt(i)) > applet.naxismax)
applet.naxismax = Integer.parseInt((String)applet.vtSent.elementAt(i));
if(Integer.parseInt((String)applet.vtRecv.elementAt(i)) > applet.naxismax)
applet.naxismax = Integer.parseInt((String)applet.vtRecv.elementAt(i));
if(Integer.parseInt((String)applet.vtSent.elementAt(i)) < applet.naxismin)
applet.naxismin = Integer.parseInt((String)applet.vtSent.elementAt(i));
if(Integer.parseInt((String)applet.vtRecv.elementAt(i)) < applet.naxismin)
applet.naxismin = Integer.parseInt((String)applet.vtRecv.elementAt(i));
}
}
applet.axisCanvas.repaint();
}
public void drawData()
{
//µ¥ÀÌŸ ±×¸®±â
int nSent = 0, nRecv = 0, nPreSent = 0, nPreRecv = 0;
float nSentRatio = 0.0f, nRecvRatio= 0.0f;
int ndrawheight = (int)(getSize().height * 2 / 3);
int ndrawgap = (int)(getSize().height / 6);
int nrange = applet.naxismax - applet.naxismin;
for(int i=0; i < applet.vtDay.size() && i < applet.vtSent.size() && i < applet.vtRecv.size() ; i++)
{
nSentRatio = (float)((float)(applet.naxismax - Integer.parseInt((String)applet.vtSent.elementAt(i))) / nrange);
nSent = (int)(nSentRatio * ndrawheight) + ndrawgap;
nRecvRatio = (float)((float)(applet.naxismax - Integer.parseInt((String)applet.vtRecv.elementAt(i))) / nrange);
nRecv = (int)(nRecvRatio * ndrawheight) + ndrawgap;
// System.out.println(nSentRatio +" " + nSent + " " + nRecvRatio + " " + nRecv);

if(applet.strType.equals("0"))
{
G.setColor(Color.blue);
G.fillRect( i * 30 + 20 - 1, nSent - 1, 3, 3);
G.setColor(Color.red);
G.fillRect( i * 30 + 20 - 1, nRecv - 1, 3, 3);
if(i > 0)
{
G.setColor(Color.blue);
G.drawLine( (i - 1) * 30 + 20 ,nPreSent , i * 30 + 20, nSent);
G.setColor(Color.red);
G.drawLine( (i - 1) * 30 + 20, nPreRecv , i * 30 + 20, nRecv);
}
}
if(applet.strType.equals("1"))
{
G.setColor(new Color(100,100,255));
if(Integer.parseInt((String)applet.vtSent.elementAt(i)) == applet.naxismin)
G.drawLine( i * 30 + 20 - 10, nSent, i * 30 + 20 - 1, nSent);
else
{
G.fillRect( i * 30 + 20 - 10, nSent, 9, -(nSent - (int)(getSize().height * 5 / 6)));
G.setColor(Color.black);
G.drawRect( i * 30 + 20 - 10, nSent, 9, -(nSent - (int)(getSize().height * 5 / 6)));
}
G.setColor(new Color(255,100,100));
if(Integer.parseInt((String)applet.vtRecv.elementAt(i)) == applet.naxismin)
G.drawLine( i * 30 + 20 + 1, nRecv, i * 30 + 20 + 10, nRecv);
else
{
G.fillRect( i * 30 + 20 + 1, nRecv, 9, -(nRecv - (int)(getSize().height * 5 / 6)));
G.setColor(Color.black);
G.drawRect( i * 30 + 20 + 1, nRecv, 9, -(nRecv - (int)(getSize().height * 5 / 6)));
}
}
G.setColor(Color.black);
G.drawString((String)(applet.vtDay.elementAt(i)),i * 30 + 20 - 8,getSize().height - 4);
G.drawString("day", getSize().width - 25 - nOriginX, getSize().height - 40);
G.drawString(applet.strYear, 5 - nOriginX, getSize().height - 52);
G.drawString(applet.strMonth, 5 - nOriginX, getSize().height - 40);

nPreSent = nSent;
nPreRecv = nRecv;
}
}

public void paint(Graphics g)
{
FontMetrics fm = g.getFontMetrics(g.getFont());
setDBuf();
setOrigin();
setOutLine();
setGrid(fm);
setRange();

drawData();

g.drawImage(backImg, 0, 0, this);
G.dispose();
backImg.flush();
pointFlag = true;
}
}

À½ ¸ÞÀÎÂ÷Æ®ÀÎ ¸¸Å­ Á¦ÀÏ ±æ±º¿ä. Çä. Á˼ÛÇÕ´Ï´Ù. x,y ÁÂÇ¥ÃàÀ» ¸¶¿ì½º¸¦ µû¶ó ±×¸®´Â ±¸ÇöÀ» Çصξú´Âµ¥, ¹Ì¿Ï¼ºÀΠä·Î ¿Ã·È±º¿ä. /* */ ó¸® Çصξú½À´Ï´Ù. ¸¶¿ì½º À̺¥Æ®´Â º¸Áö ¸¶¼¼¿ä ¤Ì.¤Ì;

ÀÏ´Ü, »ý¼ºÀÚ¸¦ º¸½Ã¸é ¹Þ¾Æ¿À±â¸¸ ÇÏ°í ÀÖ°í¿ä. ±× ¹Ø¿¡ ¾Æ±î ¸»ÇÑ sbChanged ¸Þ¼Òµå°¡ º¸ÀÌ°í¿ä. (¹°·Ð Á¦°¡ ¸¸µç ¸Þ¼ÒµåÀÔ´Ï´Ù.) ±× ´ã¿¡ º¸½Ç °ÍÀº paint¸Þ¼ÒµåÁö¿ä. setDBuf¿¡¼­ ´õºí¹öÆÛ¸µÀ» ÁغñÇÏ°í ÀÖ°í, setOrigin ¸Þ¼Òµå¿¡¼­´Â sbChanged¿¡¼­ ¹Ù²Û nOriginX¸¦ ÀÌ¿ëÇؼ­ Àüü ĵ¹ö½ºÀÇ ÁÂÇ¥ÃàÀ» translateÇØÁÖ°í ÀÖ½À´Ï´Ù. ¾Æ¿ô¶óÀÎ ±×·ÁÁÖ°í, Gridµµ ±×·ÁÁÖ°í¿ä. maximum°ú minimum°ªµµ ¿©±â¼­ º¯°æÇØÁÖ°í ÀÖÁö¿ä. setRange¸Þ¼Òµå¸¦ º¸½Ã¸é, Àüü Vectorµ¥ÀÌÅÍÀÇ Size¸¦ µ¹¸®¸é¼­ ÃÖ´ë,ÃÖ¼Ò°ªÀ» ÃßÃâÇÏ°í Àմµ¥¿ä, ¿©±â¼­ if¹®À» ÀÌ¿ëÇؼ­ º¸ÀÌ´Â ºÎºÐ¿¡ ´ëÇؼ­¸¸ ÃÖ´ë, ÃÖ¼Ò¸¦ ÁöÁ¤Çϵµ·Ï ÇÏ°í ÀÖ½À´Ï´Ù. if¹®À» »ý·«ÇϽøé, Àüü Data¸¦ °Ë»öÇؼ­ ÃÖ´ë,ÃÖ¼Ò¸¦ ÃßÃâÇÏ°ÚÁö¿ä.

drawData¿¡¼­ ½ÇÁ¦·Î ±×·ÁÁÖ°í ÀÖ½À´Ï´Ù.±×¸®°í ´õºí¹öÆÛ¸µ 󸮸¦ ÇØÁִµ¥, ´õºí¹öÆÛ¸µ¿¡ »ç¿ëÇÑ Image°´Ã¼¿Í Graphics°´Ã¼¸¦ ¼Ò°ÅÇØÁÖ´Â ºÎºÐÀ» ´«¿©°Ü ºÁÁֽøé ÁÁ°Ú½À´Ï´Ù.

³¡À̱º¿ä. ¼ö°íÇϼ̽À´Ï´Ù. ¼Ò½º ¹Þ¾Æ°¡¼¼¿ä.

¿À´ÃÀº ¿©±â±îÁö ÇÏ°í¿ä, ´ÙÀ½¹ø¿£ jdbc¸¦ ÀÌ¿ëÇؼ­ oracle¿¡¼­ µ¥ÀÌŸ¸¦ ¹Þ¾Æ¿À´Â °É ÇÑ ¹ø Çغ¼±î¿ä? ½Ã°£ÀÌ µÇ¸é C¿ÍÀÇ socketÅë½ÅÀ» ÇÏ´Â °Íµµ º¸¿©µå¸®µµ·Ï ÇÏ°Ú½À´Ï´Ù.

´õ¿î ¿©¸§Àä(ÀÌ ±Û º¸½Ç ¶§´Â °Ü¿ïÀÏÁöµµ) °Ç°­ Á¶½ÉÇϼ¼¿ä.

¼Ò½º ´Ù¿î

 

Áõ±Ç Â÷Æ® µî 3°¡ÁöÀÇ ÇÁ·ÎÁ§Æ®¸¦ º¸´Ù Ãæ½ÇÇÏ°í Ä£ÀýÇÏ°Ô ¼³¸íÇÑ

"ÀÚ¹Ù ½Ç¹« Å×Å©´Ð ºñ¹ýÀü¼ö"°¡ ¹ß°£µÇ¾ú½À´Ï´Ù.

±¸°æÇϱâ -> [http://www.50001.com/books/ ]