<JSTORM> JAVA GUI - 2 JSTORM http://wwwjstormpekr
JAVA GUI - 2 Issued by: < > Document Information Document title: JAVA GUI - 2 Document file name: Revision number: <10> Issued by: Issue Date: <2000/8/23 > Status: GUI 2_ doc < > dwjang@jkdsoftcokr : < > junoyoon@orgionet final Content Information Audience Abstract Reference Benchmark information GUI SWING - SWING SWING JSTORM <2/37>
JAVA GUI - 2 Issued by: < > Document Approvals Signature date Signature date Revision History Revision Date Author Description of change JSTORM <3/37>
JAVA GUI - 2 Issued by: < > Table of Contents 5 JComponent 6 (Visibility) (Opaqueness) 7 8 JComponent 9 MVC 12 Model, View, Controller 13 GCad 16 16 MVC17 27 (Composit) 27 JSTORM <4/37>
JAVA GUI - 2 Issued by: < > GUI! AWT GUI AWT (?) SwingSet ([ 1], SwingSet c:\jdk12\demo\jfc\swingset ), JSTORM <5/37>
JAVA GUI - 2 Issued by: < > GUI AWT GUI GUI (?) GUI ( ) GUI! Jr 5 5 5 JComponent (JApplet, JDialog, JFrame, JWindow) JComponent ([ 1][ 2] ) JComponent JComponent JComponent AWTContainer Container Component JComponent JSTORM <6/37>
JAVA GUI - 2 Issued by: < > Component Container JComponent (Visibility) (Opaqueness) JComponent ( 995 319 ) AWT JComponent 100 (Visibility) JFrame framesetvisible(true); dialogshow(); JButton buttonsetvisible(true); JButton JFrame? JFrame JButton AWT ( ) setopaque() truefalse true [ 2] 25 JSTORM <7/37>
JAVA GUI - 2 Issued by: < > ( ) [ 1] AboutDialogjava JComponent AWT AWT update() update() paint() update() update() paint() Canvas paint() AWT AWT public class GCanvas extends JPanel { public void paintcomponent(graphics g) { JSTORM <8/37>
JAVA GUI - 2 Issued by: < > JPanel AWTCanvas? AWTCanvas Canvas JCanvas Panel JPanel JPanel Canvas JPanel paintcomponent() AWT paint() paint() paintcomponent() AWT [1] paintcomponent() paintborder() paintchildren() paint() paint() [1] paint() paintcomponent() JComponent JSTORM <9/37>
JAVA GUI - 2 Issued by: < > JComponent JComponent JComponent JComponent Component Container [2] UI MVC(Model, View, Controller) MVC? [2] true setborder()? JSTORM <10/37>
JAVA GUI - 2 Issued by: < > JSTORM <11/37>
JAVA GUI - 2 Issued by: < > MVC MVC MVCModel, View, Controller MVC MVC MVC? ( ) (State) [ 2]?? [ 2], v JSTORM <12/37>
JAVA GUI - 2 Issued by: < >? 98 [ 2]? PLAF(Pluggable Look and F eel) Jr 5 MVC? (Control)? CIH Model, View, Controller [ 4] ( ) [ 4] UI JSTORM <13/37>
JAVA GUI - 2 Issued by: < > 98 ([ 3]) UI (Delegate) UI Model Model UI UI JButton ButtonModel ButtonUI UI MVC MVC JSTORM <14/37>
JAVA GUI - 2 Issued by: < > [ 1] ( ) public class GugudanModelDemo extends JFrame { public GugudanModelDemo() { super(" "); GugudanTableModel mymodel = new GugudanTableModel(); JTable table = new JTable(myModel); <<--- [1 ] getcontentpane()add(tablegettableheader(), BorderLayoutNORTH); getcontentpane()add(table, BorderLayoutCENTER); public static void main(string[] args) { GugudanModelDemo frame = new GugudanModelDemo(); framepack(); framesetvisible(true); // class GugudanTableModel extends AbstractTableModel { <<--- [2] public int getcolumncount() { return 9; public int getrowcount() { return 9; public String getcolumnname(int col) { return "" + (col+1); public Object getvalueat(int row, int col) { return new Integer((row+1)*(col+1)); [ 1][2] JSTORM <15/37>
JAVA GUI - 2 Issued by: < > AbstractTableModel [1 ] setmodel() 4 364 MVC MVC MVC MVC GCad MVC MVC MVC GEditor GEditor GCad MVC [ 5]GCad Jr GEditor GStatus GStatus,,,, GStatus GStatus JSTORM <16/37>
JAVA GUI - 2 Issued by: < > GStatus GStatus GMenu, GToolBar, GColorTable? GStatus GStatus GStatus ~ GStatusMVC GMenu, GToolBar, GColorTable MVC? GMenu, GToolBar, GColorTable GStatusBar GUI [ 5] [ 7] GStatus GStatusgetOutlineColor() (GStatusBar), [ 5] MVC GCad, GDocument, GCanvas GCad( GEditor ), GCanvas GDocument GDocument GCad ( JSTORM <17/37>
JAVA GUI - 2 Issued by: < > ) GDocument GDocument GCanvas GDocument, GCanvas, GCad MVC GDocument GCanvasGDocument GCadGDocument GDocument MVC MVC MVC [ 2] GStatus package gcad; import gcadgobject*; import gcadgui*; import javaawt*; /////////////////////////////////////////////////////////////// public class GStatus { // private int m_selectedshape = GShapeLINE; // private Color m_backgroundcolor = Colorwhite; // private Color m_outlinecolor = Colorblack; // private int m_outlinewidth = 1; // private boolean m_isfill = false; // private Color m_fillcolor = Colorwhite; // Status (Controller) (View) private GToolBar m_toolbar; private GColorTable m_colortable; private GMenu m_menu; JSTORM <18/37>
JAVA GUI - 2 Issued by: < > private GStatusBar m_statusbar; // public void settoolbar(gtoolbar toolbar) { m_toolbar = toolbar; public void setmenu(gmenu menu) { m_menu = menu; public void setstatusbar(gstatusbar statusbar) { m_statusbar = statusbar; public void setcolortable(gcolortable colortable) { m_colortable = colortable; public int getselectedshape() { return m_selectedshape; public void setselectedshape(int shape) { m_selectedshape = shape; updateviews(); <<--- [1 ] public Color getbackgroundcolor() { return m_backgroundcolor; public void setbackgroundcolor(color color) { m_backgroundcolor = color; updateviews(); public Color getoutlinecolor() { return m_outlinecolor; public void setoutlinecolor(color color) { m_outlinecolor = color; updateviews(); public int getoutlinewidth() { return m_outlinewidth; public void setoutlinewidth(int width) { m_outlinewidth = width; public boolean isfill() { return m_isfill; public void setfill(boolean fill) { m_isfill = fill; updateviews(); JSTORM <19/37>
JAVA GUI - 2 Issued by: < > public Color getfillcolor() { return m_fillcolor; public void setfillcolor(color color) { m_fillcolor = color; updateviews(); // private void updateviews() { m_toolbarupdate(); m_colortableupdate(); m_menuupdate(); m_statusbarupdate(); <<--- [2 ] [ 2] [1 ]? GStatus [1 ] [2 ] update() [ 3][1 ] update(), GStatus MVC? [ 3][2 ]? (Static initializer) (Attribute)? { package gcadgui; [ 3] GColorTable import gcad*; import javaawt*; import javaawtevent*; import javaxswing*; JSTORM <20/37>
JAVA GUI - 2 Issued by: < > ///////////////////////////////////////////////////////////////// public class GColorTable extends JPanel { /** (, ) */ private static final Dimension TABLE_SIZE = new Dimension(2, 8); /** */ private static final Dimension CELL_SIZE = new Dimension(30, 30); /** */ private static final Color[] CELL_COLORS = { ; new Color( 0, 0, 0), new Color(128, 0, 0), new Color( 0, 128, 0), new Color(128, 128, 0), new Color( 0, 0, 128), new Color(128, 0, 128), new Color( 0, 128, 128), new Color(192, 192, 192), new Color(128, 128, 128), new Color(255, 0, 0), new Color( 0, 255, 0), new Color(255, 255, 0), new Color( 0, 0, 255), new Color(255, 0, 255), new Color( 0, 255, 255), new Color(255, 255, 255) /* private static final Color[] CELL_COLORS = new Color[TABLE_SIZEheight*TABLE_SIZEwidth]; // Static initializer <<--- [2 ] { int colorcount = TABLE_SIZEheight*TABLE_SIZEwidth; for (int i=0; i<colorcount; i++) { CELL_COLORS[i] = new Color(i*(255/colorCount), 0, 0); */ // Status JSTORM <21/37>
JAVA GUI - 2 Issued by: < > private GStatus m_status; /** */ private SelectedColorCell m_selectedcolorcell; public GColorTable(GStatus status) { m_status = status; m_statussetcolortable(this); setborder(borderfactorycreateetchedborder()); // JPanel standardcolorspane = new JPanel(); standardcolorspanesetlayout(new GridLayout(0, TABLE_SIZEwidth)); for (int i=0; i<cell_colorslength; i++) { standardcolorspaneadd(new ColorCell(CELL_COLORS[i])); // m_selectedcolorcell = new SelectedColorCell(); m_selectedcolorcelladdmouselistener(new MouseAdapter() { ); public void mouseclicked(mouseevent e) { Color oldcolor = m_statusgetoutlinecolor(); Color newcolor; newcolor = JColorChoosershowDialog(null, " ", oldcolor); m_statussetoutlinecolor(newcolor); // JPanel colorpane = new JPanel(); colorpanesetlayout(new BorderLayout()); colorpaneadd(standardcolorspane, BorderLayoutNORTH); colorpaneadd(new JSeparator(SwingConstantsVERTICAL)); colorpaneadd(m_selectedcolorcell, BorderLayoutSOUTH); setlayout(new BorderLayout()); add(colorpane, BorderLayoutNORTH); JSTORM <22/37>
JAVA GUI - 2 Issued by: < > public void update() { Color color = m_statusgetoutlinecolor(); m_selectedcolorcellrepaint(); <<--- [1 ] ///////////////////////////////////////////////////////////////// /** */ private class ColorCell extends JPanel { /** */ private Color m_color; // ----------------------------------------------------------- // : public ColorCell(Color color) { m_color = color; setborder(borderfactorycreateetchedborder()); setpreferredsize(cell_size); addmouselistener(new MouseAdapter() { public void mouseclicked(mouseevent e) { m_statussetoutlinecolor(m_color); ); // ----------------------------------------------------------- public void paintcomponent(graphics g) { gsetcolor(m_color); gfilloval(2, 2, getsize()width-4, getsize()height-4); ///////////////////////////////////////////////////////////////// private class SelectedColorCell extends JPanel { // ----------------------------------------------------------- public SelectedColorCell() { setborder(borderfactorycreateetchedborder()); setpreferredsize(new Dimension( 2*CELL_SIZEwidth, 2*CELL_SIZEheight)); JSTORM <23/37>
JAVA GUI - 2 Issued by: < > // ----------------------------------------------------------- public void paintcomponent(graphics g) { Color color = m_statusgetoutlinecolor(); gsetcolor(color); gfillrect(2, 2, getsize()width-4, getsize()height-4); package gcad; [ 4] GDocument import gcadgobject*; import javautil*; import javaio*; ////////////////////////////////////////////////////////////// public class GDocument { // private Vector m_shapes = new Vector(); // public void addshape(gshape shape) { m_shapesaddelement(shape); // public Enumeration getshapes() { return m_shapeselements(); // public void clear() { m_shapesremoveallelements(); // public void save() { JSTORM <24/37>
JAVA GUI - 2 Issued by: < > // public void load() { JSTORM <25/37>
JAVA GUI - 2 Issued by: < > JSTORM <26/37>
JAVA GUI - 2 Issued by: < > [ 8] CompositGObject (Composit) CompositGObject GCad (Grouping) GCrossedRectangle? (JTextField, JTextArea, JEditorPane JTextPane ) [ 5] (Composit) 3 260 JSTORM <27/37>
JAVA GUI - 2 Issued by: < > [ 6] CompositGObject GObject (Composit) CompositGObject GObject CompositGObject GObject (implements) (is a) GObject [ 5][ 6] UML ( ) UML http://wwwrationalcom/uml/ 12 374 (implements) (extends) (Composit Aggregation) GObject, GShape, GLine [ 7][1 ] 2D 2D GEditor Graphics 2D 2D JDK 2D [ 5] GObject JSTORM <28/37>
JAVA GUI - 2 Issued by: < > package gcadgobject; import javaawt*; import javaio*; ///////////////////////////////////////////////////////////////// public interface GObject extends Serializable { // public abstract void draw(graphics g); // public abstract void erase(graphics g); [ 6] GShape package gcadgobject; import javaawt*; ///////////////////////////////////////////////////////////////// public abstract class GShape implements GObject { // public static final int LINE = 1; public static final int RECTANGLE = 2; public static final int SQUARE = 3; public static final int ELLIPSE = 4; public static final int CIRCLE = 5; // protected Color m_outlinecolor = Colorblack; // protected int m_outlinewidth = 1; // protected boolean m_isfill = false; JSTORM <29/37>
JAVA GUI - 2 Issued by: < > // protected Color m_fillcolor = Colorwhite; // public Color getoutlinecolor() { return m_outlinecolor; public void setoutlinecolor(color color) { m_outlinecolor = color; public int getoutlinewidth() { return m_outlinewidth; public void setoutlinewidth(int width) { m_outlinewidth = width; public boolean isfill() { return m_isfill; public void setfill(boolean fill) { m_isfill = fill; public Color getfillcolor() { return m_fillcolor; public void setfillcolor(color color) { m_fillcolor = color; // ( ) public abstract void setpenposition(point point); // public void erase(graphics g) { gsetxormode(colorwhite); draw(g); [ 7] GLine package gcadgobject; import javaawt*; ///////////////////////////////////////////////////////////////// public class GLine extends GShape { // private Point m_startpoint; // private Point m_ endpoint; JSTORM <30/37>
JAVA GUI - 2 Issued by: < > public GLine(Point point) { m_startpoint = point; m_endpoint = point; // ( ) public void setpenposition(point point) { m_endpoint = point; // public void draw(graphics g) { Graphics2D g2 = (Graphics2D)g; <<--- [1 ] Stroke oldstroke = g2getstroke(); g2setstroke(new BasicStroke(m_outlineWidth)); g2setcolor(m_outlinecolor); g2drawline(m_startpointx, m_startpointy, m_endpointx, m_endpointy); g2setstroke(oldstroke); GCad JSTORM <31/37>
JAVA GUI - 2 Issued by: < > JSTORM <32/37>
JAVA GUI - 2 Issued by: < > JSTORM <33/37>
JAVA GUI - 2 Issued by: < > JSTORM <34/37>
JAVA GUI - 2 Issued by: < > JSTORM <35/37>
JAVA GUI - 2 Issued by: < > JSTORM <36/37>
JAVA GUI - 2 Issued by: < > JSTORM <37/37>