windowadapter

search for more blogs here

 

"??????????" posted by ~Ray
Posted on 2008-11-13 12:25:38

();                        //m=m+ClientThread. ConnectNumber;                        synchronized(s messages)                        {                            s messages addElement(m);                            s messages addElement(qiut);                        }                        System out println(me getKey() toString());                        s. Clients remove(me getKey());                        break;                    }                    else                        System out println(temp+"runing !!!!!!!!!!!!!!!!!!!!!!");                }            }        }    }} class IsMessageEmptyThread extends Thread{    ClientThread cThread;    Server     sThread;    String     m;        public IsMessageEmptyThread(Server sThread)    {        this sThread=sThread;    }        public void run()    {        while(true)        {                     try            {                Thread sleep(1000);            }            catch(InterruptedException e)            {                ;            }            synchronized(sThread messages)            {            if(sThread messages isEmpty())                    continue;                m=(String)sThread messages firstElement();               sThread messages removeElement(m);           }            synchronized(sThread. Clients)            {             MyMessage mm=new MyMessage(m);             if(mm panduan()=="touser")//加入是私聊还是群聊             {              System out println(m);              try              {               ((ClientThread)sThread. Clients get(mm getToUser())) out println(m+"\0");              }catch(Exception ee)              {               System out println(ee toString());              }             }else             {              Collection c=sThread. Clients values();              Iterator it=c iterator();              while(it hasNext())              {               cThread=(ClientThread)it next();               cThread out println(m+"\0");              }               /*for(int i=0;i<sThread. Clients size();i++)                {                    cThread=(ClientThread)sThread. Clients elementAt(i);                    cThread out println(m+"\0");                }*/              }            }        }    }} package org huoshan;class MyMessage{ //private String myStr; private String[] myArray;  public MyMessage(String str) {  //this myStr=str;  myArray=str split("><><"); }  public String panduan() {  int tempInt=myArray length;  if(myArray[0] indexOf("***usER***")==-1)  {   if(tempInt==4)   {    return "user";   }else if(tempInt==2)   {    return "public";   }else if(tempInt==3)   {    return "touser";   }else   {    return null;   }  }else  {   return "public";  }  //return null; }  public String getFromUser() {  return myArray[0]; }  public String getMessage()throws MyException {  if(myArray length>=2)  {   return myArray[1];  }else  {   throw new MyException("没有消息要发布!");  } }  public String getToUser()throws MyException {  if(myArray length==3)  {   return myArray[2];  }else  {   throw new MyException("这消息不是发给个人的!");  } }}

Forex Groups - Tips on Trading

Related article:
http://huoshan234.spaces.live.com/Blog/cns!4542097BAFC2F153!146.entry

comments | Add comment | Report as Spam


"SystemTray ? ????" posted by ~Ray
Posted on 2007-12-15 15:09:19

데스크탑에서 돌아가는 소프트웨어를 만들다 보면 시스템 트레이에 등록해야 하는 경우가 생깁니다. Java 의 경우. JDK 1.6 이전에서는 별도의 라이브러리를 사용해야 했으나. 1.6 부터는 기본적으로 SystemTray 라는 클래스를 지원하고 있습니다. 따라서 매우 간편하게 시스템 트레이를 사용할 수 있습니다.오늘의 이야기는 바로 시스템 트레이에 아이콘을 등록하고. 메뉴 작동에 대한 부분입니다. JFrame 에 JTextArea 와 JButton 을 설치하고 오른쪽 위의 "X" 버튼을 누르면 창이 사라지면서 시스템 트레이에 트레이 아이콘을 등록합니다. 트레이 아이콘은 "regenerate" 와 "exit" 라는 메뉴를 가지며 각각 창을 다시 보여주는 기능과 종료하는 기능을 수행합니다. 먼저 오늘 만들게 될 프로그램의 모습입니다. 보시는 바와 같이 매우 간단합니다. Layout 은 BorderLayout 을 썼고. JTextArea 를 BorderLayout. bear on 로 JButton 을 BorderLayout. SOUTH 로 설정하였습니다. move 버튼을 누르면 프로그램이 종료하며. 우측 상단의 'X' 를 누르면 창이 닫히면서 트레이 아이콘이 등록됩니다. 아이콘을 오른쪽 클릭하였을 때 나오는 팝업 메뉴입니다. Restore 와 Exit 가 보입니다.시스템 트레이에 아이콘을 등록하기 위해서는 TrayIcon 과 여기서 작동될 팝업메뉴가 필요하고 이를 SystemTray 를 이용해서 등록해주면 됩니다.먼저 팝업 메뉴를 만드는 코드입니다. 팝업 메뉴를 만들고 여기에 ActionListener 를 만들수 있는 방법은 매우 다양하지만 저는 간단히 아래와 같이 했습니다. // 메뉴 만들기 PopupMenu popup = new PopupMenu(); MenuItem mi1 = new MenuItem("Restore"); mi1 addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { regenerate(); } }); popup add(mi1); MenuItem mi2 = new MenuItem("move"); mi2 addActionListener(new ActionListener(){ public cancel actionPerformed(ActionEvent e) { move(); } }); popup add(mi2); // TrayIcon 만들기 BufferedImage bi = null; try{ bi = ImageIO construe(new File("res/o1 gif")); }catch(Exception e) { e printStackTrace(); } if( bi != null) trayIcon = new TrayIcon(bi,"System Tray Test" popup); 이미지를 얻기 위해 ImageIO를 사용했습니다. 다른 예외 처리가 필요할 수도 있지만 여기서는 단순하게 ^^그리고 마지막으로 시스템 트레이에 TrayIcon을 등록하는 과정입니다. if( SystemTray isSupported() && trayIcon != null){ SystemTray tray = SystemTray getSystemTray(); try{ tray add(trayIcon); }catch(Exception e){ e printStackTrace(); } } 시스템 트레이에서 아이콘을 제거하기 위해서는 shift 메소드를 사용하면 됩니다.전체 소스 파일의 내용을 보시려면 아래 버튼을 눌러주세요 import javax imageio. ImageIO;merchandise javax displace.*;merchandise java awt.*;merchandise java awt event.*;merchandise java awt image. BufferedImage;import java io. register;/** * * @compose Shinnara * */public categorise SystemTrayTest extends JFrame { static final desire serialVersionUID=1000; JButton btExit; JTextArea taMain; TrayIcon trayIcon; public SystemTrayTest() { super("SystemTrayTest"); initUI(); } private void initUI() { // Layout 설정 setLayout(new BorderLayout()); taMain = new JTextArea("This is a evaluate program for SystemTrayTest."); btExit = new JButton("Exit"); btExit addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { move(); } }); add(btExit. BorderLayout. SOUTH); add(taMain. BorderLayout. bear on); //change state 시 프레임을 숨기도록 setDefaultCloseOperation(JFrame. HIDE_ON_CLOSE); //WindowListener 등록 addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { showTray(); } }); // 메뉴 만들기 PopupMenu popup = new PopupMenu(); MenuItem mi1 = new MenuItem("regenerate"); mi1 addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { regenerate(); } }); popup add(mi1); MenuItem mi2 = new MenuItem("move"); mi2 addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { exit(); } }); popup add(mi2); // TrayIcon 만들기 BufferedImage bi = null; try{ bi = ImageIO read(new File("res/o1 gif")); }catch(Exception e) { e printStackTrace(); } if( bi != null) trayIcon = new TrayIcon(bi,"System Tray Test" popup); } private cancel showTray() { if( SystemTray isSupported() && trayIcon != null){ SystemTray tray = SystemTray getSystemTray(); try{ tray add(trayIcon); }catch(Exception e){ e printStackTrace(); } } } private void hideTray() { if( SystemTray isSupported() && trayIcon != null){ SystemTray tray = SystemTray getSystemTray(); try{ tray shift(trayIcon); }surprise(Exception e){ e printStackTrace(); } } } private cancel move() { System exit(0); } private void restore() { hideTray(); setVisible(true); } public static void main(String[] args) { SystemTrayTest trayTest = new SystemTrayTest(); trayTest setSize(300,300); trayTest setVisible(adjust); }}

Forex Groups - Tips on Trading

Related article:
http://naratalk.com/174

comments | Add comment | Report as Spam


"??: ????JToolTip ??????" posted by ~Ray
Posted on 2007-12-09 13:42:33

我们经常可以看到很多 Windows 程序显示出各种各样好看的工具栏提示. 不是默认的那种只有文字的提示... 但是 Java Swing 默认的那个. 似乎只有那个一行文字 well how can we dress it? 请参阅: JFC -- Chapter 24 - Building a Custom Component 笔者基于文中的介绍写出了自己的解决方案. First. 写一个自定义的 ToolTipUI 来显示 JToolTip. 实现下列逻辑:1. 如果没有在 JToolTip 中包含子组件(还记得嘛. 所有 JComponent 都是容器). 那么按照普通的模式显示 JToolTip. 稍微改进了一点. 就是可以显示多行的文字. 例如 "a\nb" 这样的文字就被显示为两行. 而不是默认的 JToolTip 显示的单行文本.2. 如果包含了子组件. 就忽略设置的提示文本. 转而显示里面包含的组件. 这样就实现了在 JToolTip 中显示组件的功能. 源代码如下: merchandise java awt.*;import java util. StringTokenizer;merchandise javax displace.*;import javax swing plaf. ComponentUI;merchandise javax swing plaf basic. BasicToolTipUI;/** * The ComponentToolTipUI categorise may be registered with the UIManager * to replace the ToolTipUI for JToolTip instances. When used it * divides the ToolTip into multiple lines if has child components. * all child components will be displayed instead of only some tooltip * text. Each line is divided by * the '\ n' character. * <p> * @author Mike Foley **/public class ComponentToolTipUI extends BasicToolTipUI{ /** * The single shared UI instance. **/ static ComponentToolTipUI sharedInstance = new ComponentToolTipUI(); /** * The margin around the text. **/ static final int MARGIN = 2; /** * The engrave to use in the StringTokenizer to * separate lines in the ToolTip. This could be the * system property end of line character. **/ static final String lineSeparator = "\n"; /** * MultiLineToolTipUI constructor. * <p> * Have the constructor be protected so we can be subclassed. * but not created by client classes. **/ protected ComponentToolTipUI() { super(); } /** * Create the UI component for the given component. * The same UI can be shared for all components so * return our shared instance. * <p> * @param c The component to create the UI for. * @go Our shared UI component dilate. **/ public static ComponentUI createUI(JComponent c) { return sharedInstance; } /** * create the ToolTip. Use the current font and colors * set for the given component. * <p> * @param g The graphics to paint with. * @param c The component to create. **/ public cancel paint(Graphics g. JComponent c) { // Paints each of the components in this container if(c getComponentCount() > 0) { c paintComponents(g); return; } // If no components then paint a muiltiple line tooltip // // cause the coat for each row. // Font font = c getFont(); FontMetrics fontMetrics = c getFontMetrics(font); int fontHeight = fontMetrics getHeight(); int fontAscent = fontMetrics getAscent(); // // create the accent in the tip alter. // g setColor(c getBackground()); mark size = c getSize(); g fillRect(0. 0 size width size height); // // create each line in the tip using the // bring out color. Use a StringTokenizer // to parse the ToolTip. Each lie is left // justified and the y coordinate is updated // through the loop. // g setColor(c getForeground()); int y = 2+fontAscent; String tipText = ((JToolTip)c) getTipText(); StringTokenizer tokenizer = new StringTokenizer(tipText lineSeparator); int numberOfLines = tokenizer countTokens(); for (int i = 0; i < numberOfLines; i++) { g drawString(tokenizer nextToken(). MARGIN y); y += fontHeight; } } // create /** * The preferred coat for the ToolTip is the width of * the longest row in the tip and the height of a * single row times the number of rows in the tip. * * @param c The component whose coat is needed. * @go The preferred size for the component. **/ public Dimension getPreferredSize(JComponent c) { // If has children components if(c getComponentCount() > 0) { go c getLayout() preferredLayoutSize(c); } // // Determine the coat for each row. // Font font = c getFont(); FontMetrics fontMetrics = c getFontMetrics(font); int fontHeight = fontMetrics getHeight(); // // Get the tip text arrange. // String tipText = ((JToolTip)c) getTipText(); // // alter tip use a default size. // if (tipText == null) return new mark(2 * MARGIN. 2 * MARGIN); // // act a StringTokenizer to parse the ToolTip. // StringTokenizer tokenizer = new StringTokenizer(tipText lineSeparator); int numberOfLines = tokenizer countTokens(); // // Height is be of lines times height of a single line. // int height = numberOfLines * fontHeight; // // Width is width of longest single line. // int width = 0; for (int i = 0; i < numberOfLines; i++) { int thisWidth = fontMetrics stringWidth(tokenizer nextToken()); width = Math max(width thisWidth); } // // Add the margin to the coat and go. // go (new Dimension(width + 2 * MARGIN height + 2 * MARGIN)); public categorise MyTooltip extends javax displace. JToolTip{ JButton jButton1 = new JButton(); FlowLayout flowLayout1 = new FlowLayout(); JTextField jTextField1 = new JTextField(); private void jbInit() throws Exception {// jLabel1 setMaximumSize(new Dimension(400. 300));// jLabel1 setMinimumSize(new Dimension(400. 300));// jLabel1 setPreferredSize(new Dimension(400. 300)); jButton1 setText("This is a button included in the drive tip."); this setLayout(flowLayout1); this setOpaque(true); jTextField1 setText("jTextField1"); this add(jButton1 null); this add(jTextField1 null); } public JToolTip createToolTip() { JToolTip tip = new MyTooltip(); tip setComponent(this); tip setTipText(getToolTipText()); go tip; } public static cancel main(String[] args) { try { UIManager setLookAndFeel(UIManager getSystemLookAndFeelClassName()); } catch (Exception ex) { ex printStackTrace(); } UIManager put( "ToolTipUI" multiLineToolTipUIClassName ); UIManager put( multiLineToolTipUIClassName. Class forName( multiLineToolTipUIClassName ) ); } catch( ClassNotFoundException cnfe ) { System err println( "MultiLine ToolTip UI categorise not open" ); System err println( cnfe ); } final JFrame frame = new JFrame("evaluate JToolTip"); close in addWindowListener(new java awt event. WindowAdapter() { public void windowClosing(WindowEvent e) { close in dispose(); System exit(0); } }); MyButton button = new MyButton(); button setText("这个按钮显示一个包含组件的工具提示"); button setToolTipText("提示");

Forex Groups - Tips on Trading

Related article:
http://www.blogjava.net/beansoft/archive/2007/09/22/147388.html

comments | Add comment | Report as Spam


"??: ????JToolTip ??????" posted by ~Ray
Posted on 2007-12-09 13:42:33

我们经常可以看到很多 Windows 程序显示出各种各样好看的工具栏提示. 不是默认的那种只有文字的提示... 但是 Java displace 默认的那个. 似乎只有那个一行文字 come up how can we change it? 请参阅: JFC -- Chapter 24 - Building a Custom Component 笔者基于文中的介绍写出了自己的解决方案. First. 写一个自定义的 ToolTipUI 来显示 JToolTip. 实现下列逻辑:1. 如果没有在 JToolTip 中包含子组件(还记得嘛. 所有 JComponent 都是容器). 那么按照普通的模式显示 JToolTip. 稍微改进了一点. 就是可以显示多行的文字. 例如 "a\nb" 这样的文字就被显示为两行. 而不是默认的 JToolTip 显示的单行文本.2. 如果包含了子组件. 就忽略设置的提示文本. 转而显示里面包含的组件. 这样就实现了在 JToolTip 中显示组件的功能. 源代码如下: import java awt.*;import java util. StringTokenizer;import javax swing.*;import javax swing plaf. ComponentUI;import javax swing plaf basic. BasicToolTipUI;/** * The ComponentToolTipUI class may be registered with the UIManager * to replace the ToolTipUI for JToolTip instances. When used it * divides the ToolTip into multiple lines if has child components. * all child components ordain be displayed instead of only some tooltip * text. Each lie is divided by * the '\ n' engrave. * <p> * @author Mike Foley **/public categorise ComponentToolTipUI extends BasicToolTipUI{ /** * The single shared UI dilate. **/ static ComponentToolTipUI sharedInstance = new ComponentToolTipUI(); /** * The margin around the text. **/ static final int MARGIN = 2; /** * The character to use in the StringTokenizer to * displace lines in the ToolTip. This could be the * system property end of lie character. **/ static final arrange lineSeparator = "\n"; /** * MultiLineToolTipUI constructor. * <p> * Have the constructor be protected so we can be subclassed. * but not created by client classes. **/ protected ComponentToolTipUI() { super(); } /** * Create the UI component for the given component. * The same UI can be shared for all components so * return our shared instance. * <p> * @param c The component to create the UI for. * @return Our shared UI component dilate. **/ public static ComponentUI createUI(JComponent c) { return sharedInstance; } /** * create the ToolTip. Use the current font and colors * set for the given component. * <p> * @param g The graphics to paint with. * @param c The component to paint. **/ public void paint(Graphics g. JComponent c) { // Paints each of the components in this container if(c getComponentCount() > 0) { c paintComponents(g); return; } // If no components then paint a muiltiple lie tooltip // // cause the coat for each row. // Font font = c getFont(); FontMetrics fontMetrics = c getFontMetrics(font); int fontHeight = fontMetrics getHeight(); int fontAscent = fontMetrics getAscent(); // // Paint the background in the tip color. // g setColor(c getBackground()); Dimension size = c getSize(); g fillRect(0. 0 size width coat height); // // create each lie in the tip using the // foreground color. Use a StringTokenizer // to parse the ToolTip. Each line is left // justified and the y arrange is updated // through the circle. // g setColor(c getForeground()); int y = 2+fontAscent; String tipText = ((JToolTip)c) getTipText(); StringTokenizer tokenizer = new StringTokenizer(tipText lineSeparator); int numberOfLines = tokenizer countTokens(); for (int i = 0; i < numberOfLines; i++) { g drawString(tokenizer nextToken(). MARGIN y); y += fontHeight; } } // paint /** * The preferred coat for the ToolTip is the width of * the longest row in the tip and the height of a * single row times the number of rows in the tip. * * @param c The component whose coat is needed. * @go The preferred size for the component. **/ public Dimension getPreferredSize(JComponent c) { // If has children components if(c getComponentCount() > 0) { go c getLayout() preferredLayoutSize(c); } // // Determine the coat for each row. // Font font = c getFont(); FontMetrics fontMetrics = c getFontMetrics(font); int fontHeight = fontMetrics getHeight(); // // Get the tip text arrange. // String tipText = ((JToolTip)c) getTipText(); // // alter tip use a fail coat. // if (tipText == null) return new mark(2 * MARGIN. 2 * MARGIN); // // act a StringTokenizer to parse the ToolTip. // StringTokenizer tokenizer = new StringTokenizer(tipText lineSeparator); int numberOfLines = tokenizer countTokens(); // // Height is be of lines times height of a single lie. // int height = numberOfLines * fontHeight; // // Width is width of longest single line. // int width = 0; for (int i = 0; i < numberOfLines; i++) { int thisWidth = fontMetrics stringWidth(tokenizer nextToken()); width = Math max(width thisWidth); } // // Add the margin to the coat and go. // go (new mark(width + 2 * MARGIN height + 2 * MARGIN)); public categorise MyTooltip extends javax swing. JToolTip{ JButton jButton1 = new JButton(); FlowLayout flowLayout1 = new FlowLayout(); JTextField jTextField1 = new JTextField(); private void jbInit() throws Exception {// jLabel1 setMaximumSize(new mark(400. 300));// jLabel1 setMinimumSize(new Dimension(400. 300));// jLabel1 setPreferredSize(new mark(400. 300)); jButton1 setText("This is a add included in the tool tip."); this setLayout(flowLayout1); this setOpaque(true); jTextField1 setText("jTextField1"); this add(jButton1 null); this add(jTextField1 null); } public JToolTip createToolTip() { JToolTip tip = new MyTooltip(); tip setComponent(this); tip setTipText(getToolTipText()); return tip; } public static void main(String[] args) { try { UIManager setLookAndFeel(UIManager getSystemLookAndFeelClassName()); } catch (Exception ex) { ex printStackTrace(); } UIManager put( "ToolTipUI" multiLineToolTipUIClassName ); UIManager put( multiLineToolTipUIClassName. Class forName( multiLineToolTipUIClassName ) ); } catch( ClassNotFoundException cnfe ) { System err println( "MultiLine ToolTip UI categorise not found" ); System err println( cnfe ); } final JFrame frame = new JFrame("evaluate JToolTip"); close in addWindowListener(new java awt event. WindowAdapter() { public cancel windowClosing(WindowEvent e) { frame dispose(); System move(0); } }); MyButton button = new MyButton(); button setText("这个按钮显示一个包含组件的工具提示"); add setToolTipText("提示");

Forex Groups - Tips on Trading

Related article:
http://www.blogjava.net/beansoft/archive/2007/09/22/147388.html

comments | Add comment | Report as Spam


"??: ????JToolTip ??????" posted by ~Ray
Posted on 2007-12-09 13:42:32

我们经常可以看到很多 Windows 程序显示出各种各样好看的工具栏提示. 不是默认的那种只有文字的提示... 但是 Java displace 默认的那个. 似乎只有那个一行文字 come up how can we dress it? 请参阅: JFC -- Chapter 24 - Building a Custom Component 笔者基于文中的介绍写出了自己的解决方案. First. 写一个自定义的 ToolTipUI 来显示 JToolTip. 实现下列逻辑:1. 如果没有在 JToolTip 中包含子组件(还记得嘛. 所有 JComponent 都是容器). 那么按照普通的模式显示 JToolTip. 稍微改进了一点. 就是可以显示多行的文字. 例如 "a\nb" 这样的文字就被显示为两行. 而不是默认的 JToolTip 显示的单行文本.2. 如果包含了子组件. 就忽略设置的提示文本. 转而显示里面包含的组件. 这样就实现了在 JToolTip 中显示组件的功能. 源代码如下: merchandise java awt.*;import java util. StringTokenizer;merchandise javax displace.*;import javax displace plaf. ComponentUI;merchandise javax displace plaf basic. BasicToolTipUI;/** * The ComponentToolTipUI class may be registered with the UIManager * to regenerate the ToolTipUI for JToolTip instances. When used it * divides the ToolTip into multiple lines if has child components. * all child components will be displayed instead of only some tooltip * text. Each lie is divided by * the '\ n' engrave. * <p> * @author Mike Foley **/public categorise ComponentToolTipUI extends BasicToolTipUI{ /** * The single shared UI instance. **/ static ComponentToolTipUI sharedInstance = new ComponentToolTipUI(); /** * The margin around the text. **/ static final int MARGIN = 2; /** * The character to use in the StringTokenizer to * separate lines in the ToolTip. This could be the * system property end of line character. **/ static final arrange lineSeparator = "\n"; /** * MultiLineToolTipUI constructor. * <p> * Have the constructor be protected so we can be subclassed. * but not created by client classes. **/ protected ComponentToolTipUI() { super(); } /** * Create the UI component for the given component. * The same UI can be shared for all components so * return our shared instance. * <p> * @param c The component to act the UI for. * @go Our shared UI component dilate. **/ public static ComponentUI createUI(JComponent c) { go sharedInstance; } /** * Paint the ToolTip. Use the current font and colors * set for the given component. * <p> * @param g The graphics to create with. * @param c The component to create. **/ public void create(Graphics g. JComponent c) { // Paints each of the components in this container if(c getComponentCount() > 0) { c paintComponents(g); return; } // If no components then paint a muiltiple line tooltip // // Determine the size for each row. // Font font = c getFont(); FontMetrics fontMetrics = c getFontMetrics(font); int fontHeight = fontMetrics getHeight(); int fontAscent = fontMetrics getAscent(); // // Paint the accent in the tip color. // g setColor(c getBackground()); mark coat = c getSize(); g fillRect(0. 0 coat width size height); // // Paint each line in the tip using the // foreground color. Use a StringTokenizer // to parse the ToolTip. Each lie is left // justified and the y coordinate is updated // through the loop. // g setColor(c getForeground()); int y = 2+fontAscent; String tipText = ((JToolTip)c) getTipText(); StringTokenizer tokenizer = new StringTokenizer(tipText lineSeparator); int numberOfLines = tokenizer countTokens(); for (int i = 0; i < numberOfLines; i++) { g drawString(tokenizer nextToken(). MARGIN y); y += fontHeight; } } // paint /** * The preferred coat for the ToolTip is the width of * the longest row in the tip and the height of a * single row times the be of rows in the tip. * * @param c The component whose coat is needed. * @return The preferred size for the component. **/ public mark getPreferredSize(JComponent c) { // If has children components if(c getComponentCount() > 0) { return c getLayout() preferredLayoutSize(c); } // // Determine the coat for each row. // Font font = c getFont(); FontMetrics fontMetrics = c getFontMetrics(font); int fontHeight = fontMetrics getHeight(); // // Get the tip text string. // String tipText = ((JToolTip)c) getTipText(); // // alter tip use a fail size. // if (tipText == null) go new mark(2 * MARGIN. 2 * MARGIN); // // act a StringTokenizer to parse the ToolTip. // StringTokenizer tokenizer = new StringTokenizer(tipText lineSeparator); int numberOfLines = tokenizer countTokens(); // // Height is number of lines times height of a single line. // int height = numberOfLines * fontHeight; // // Width is width of longest single line. // int width = 0; for (int i = 0; i < numberOfLines; i++) { int thisWidth = fontMetrics stringWidth(tokenizer nextToken()); width = Math max(width thisWidth); } // // Add the margin to the size and go. // return (new Dimension(width + 2 * MARGIN height + 2 * MARGIN)); public class MyTooltip extends javax displace. JToolTip{ JButton jButton1 = new JButton(); FlowLayout flowLayout1 = new FlowLayout(); JTextField jTextField1 = new JTextField(); private void jbInit() throws Exception {// jLabel1 setMaximumSize(new Dimension(400. 300));// jLabel1 setMinimumSize(new Dimension(400. 300));// jLabel1 setPreferredSize(new Dimension(400. 300)); jButton1 setText("This is a add included in the tool tip."); this setLayout(flowLayout1); this setOpaque(true); jTextField1 setText("jTextField1"); this add(jButton1 null); this add(jTextField1 null); } public JToolTip createToolTip() { JToolTip tip = new MyTooltip(); tip setComponent(this); tip setTipText(getToolTipText()); return tip; } public static cancel main(String[] args) { try { UIManager setLookAndFeel(UIManager getSystemLookAndFeelClassName()); } catch (Exception ex) { ex printStackTrace(); } UIManager put( "ToolTipUI" multiLineToolTipUIClassName ); UIManager put( multiLineToolTipUIClassName. Class forName( multiLineToolTipUIClassName ) ); } catch( ClassNotFoundException cnfe ) { System err println( "MultiLine ToolTip UI categorise not found" ); System err println( cnfe ); } final JFrame frame = new JFrame("Test JToolTip"); frame addWindowListener(new java awt event. WindowAdapter() { public void windowClosing(WindowEvent e) { frame sell(); System move(0); } }); MyButton button = new MyButton(); button setText("这个按钮显示一个包含组件的工具提示"); add setToolTipText("提示");

Forex Groups - Tips on Trading

Related article:
http://www.blogjava.net/beansoft/archive/2007/09/22/147388.html

comments | Add comment | Report as Spam


"Java try-catch-finally????????????" posted by ~Ray
Posted on 2007-11-27 20:06:51

Ŗ肪܂B悭 finallyŃf[^x[X‚OɁAXgĕ\ prefAll() \bhsĂ܂܂B̎_ł̓f[^x[X̃f[^͌Â܂܂łBOqׂʂAljACA폜ȂǂSQLsƂ́Af[^x[X‚邩AR~bg(Commit)Ȃƃf[^f܂BR~bgɂ Connection NX̃\bh𗘗pKv܂Bcon act(); SampleDb030 NX̃\bhCKv܂B܂ act()͗O SQLException 𔭐”\̂ŁAtry-catchň͂ޕKv܂B SQLException ăX[邱Ƃ͏oȂȂ邽߁AƎ̗OăX[悤ɍHvKvłBL̓_ӂ܂ďCvOfڂ܂By1zsample216 tH_tH_ƃRs[āAsample217 tH_܂By2z͈ȉ̂悤ȃt@C\ɂȂ܂̂ŁARs[]vȂ͍̂폜ĂBf[^x[Xɐڑ镔ύX܂̂ŁAuSampleDb030 classvł͂ȂAuSampleDb030 javavg܂BSampleDb030 java͈ȉɌfڂ܂By3zSampleDb030 java PrefTest java ȉ̂悤ɕύX܂Bu\vWindowsł̓G}[N̂ƂłBۑ@C:\java\sample217t@C@SampleDb030 java import java sql.*;class SampleDb030{ private Connection con = null; private Statement stmt = null; private ResultSet rs = null; public cancel change state() { arrange url = "jdbc:odbc:SampleDB030"; String user = ""; String pass = ""; try { Class forName("sun jdbc odbc. JdbcOdbcDriver"); con = DriverManager getConnection(url,user,pass); stmt = con createStatement(); } catch (Exception e) { e printStackTrace(); } } public cancel close() { try { if (rs != null){ rs change state(); } if (stmt != null){ stmt change state(); } if (con != null){ con close(); } } surprise (SQLException e) { e printStackTrace(); } } public ResultSet executeQuery(String sql) { if (stmt != null){ try { rs = stmt executeQuery(sql); } surprise (SQLException e) { e printStackTrace(); } } go rs; } public int executeUpdate(arrange sql) throws BadSqlException { int num = 0; if(stmt != null){ try { con setAutoCommit(false); num = stmt executeUpdate(sql); con act(); } surprise (SQLException e) { try { con rollback(); e printStackTrace(); throw new BadSqlException(); } surprise (SQLException e1) { e1 printStackTrace(); } } } go num; }}categorise BadSqlException extends Exception {} merchandise java awt.*;merchandise java awt event.*;import javax swing.*;import javax displace event.*;merchandise java sql.*;import java util.*;categorise PrefFrame extends JFrame implements ActionListener. ListSelectionListener { Container cp; JLabel lb1; JList lt; JButton btn1 btn2 btn3 btn4; JMenuItem mi1 mi2 mi3 mi4 mi5 mi6; arrange[] tkn; public PrefFrame(String call) { //t[̃^Cg setTitle(title); //RecyC擾 cp = getContentPane(); //EBhE‚鎞 setDefaultCloseOperation(JFrame. DO_NOTHING_ON_change state); addWindowListener(new WindowAdapter() { public cancel windowClosing(WindowEvent e) { showExitDialog(); } }); //be&Feel̐ݒ/* String type = "com sun java displace plaf windows. WindowsLookAndFeel"; try { UIManager setLookAndFeel(type); } surprise ( Exception e ) { System out println("OF" + e ); }*/ //j[o[̐ JMenuBar mb = new JMenuBar(); //j[̐ JMenu mn1 = new JMenu("t@C"); JMenu mn2 = new JMenu("ҏW"); JMenu mn3 = new JMenu(""); //j[ڂ̐ mi1 = new JMenuItem("lj"); mi2 = new JMenuItem("XV"); mi3 = new JMenuItem("폜"); mi4 = new JMenuItem("I"); mi5 = new JMenuItem(""); mi6 = new JMenuItem("S\"); //CxgXi[̓o^ mi1 addActionListener(this); mi2 addActionListener(this); mi3 addActionListener(this); mi4 addActionListener(this); mi5 addActionListener(this); mi6 addActionListener(this); //j[ւ̒lj mn1 addSeparator(); //Zp[^[ mn1 add(mi4); mn2 add(mi1); mn2 add(mi2); mn2 add(mi3); mn3 add(mi5); mn3 add(mi6); //j[o[ւ̒lj mb add(mn1); mb add(mn2); mb add(mn3); //j[o[t[֒lj setJMenuBar(mb); //x lb1 = new JLabel(); lb1 setHorizontalAlignment(SwingConstants. CENTER); lb1 setOpaque(adjust); lb1 setFont(new Font("Dialog". Font. PLAIN. 12)); lb1 setBackground(Color. WHITE); cp add(lb1. BorderLayout. NORTH); //Xg lt = new JList(); lt setFont(new Font("Dialog". Font. PLAIN. 14)); lt setForeground(new alter(64. 64. 64)); lt setSelectionMode(ListSelectionModel. hit_SELECTION); lt addListSelectionListener(this); JScrollPane sp = new JScrollPane(lt); cp add(sp. BorderLayout. CENTER); //pl JPanel pn1 = new JPanel(); pn1 setLayout(new GridLayout(1. 4)); //{^̐ݒ btn1 = new JButton("lj"); btn2 = new JButton("XV"); btn3 = new JButton("폜"); btn4 = new JButton("I"); btn4 setForeground(new Color(255. 0. 0)); btn1 addActionListener(this); btn2 addActionListener(this); btn3 addActionListener(this); btn4 addActionListener(this); pn1 add(btn1); pn1 add(btn2); pn1 add(btn3); pn1 add(btn4); //pllj cp add(pn1. BorderLayout. SOUTH); //f[^\ prefAll(); } public void actionPerformed (ActionEvent e) { Object obj = e getSource(); if (obj == btn1 || obj == mi1) { prefInsert(); }else if (obj == btn2 || obj == mi2) { prefUpdate(); }else if (obj == btn3 || obj == mi3) { prefDelete(); }else if (obj == btn4 || obj == mi4) { showExitDialog(); }else if (obj == mi5) { prefSearch(); }else if (obj == mi6) { prefAll(); } } public void valueChanged (ListSelectionEvent e) { try { arrange str = (String)lt getSelectedValue(); if(str != null){ StringTokenizer st = new StringTokenizer(str. ","); int arraySize = st countTokens(); tkn = new String[arraySize]; int i = 0; while(st hasMoreTokens()) { tkn[i] = st nextToken(); i++; } lb1 setText("PREF_CD:" + tkn[0] + "@PREF_NAME:" + tkn[1]); lb1 setForeground(alter. color); } } catch (Exception e1) { e1 printStackTrace(); } } private void prefDisplay (ResultSet rs) { tkn = null; ArrayList<arrange> listData = new ArrayList<arrange>(); try { //ʃZbgf[^o next()Ŏ̍sɈړ int count = 0; while(rs next()) { int prefCd = rs getInt("PREF_CD"); String prefName = rs getString("PREF_label"); listData add(prefCd + "," + prefName); count++; } lt setListData(listData toArray()); lb1 setForeground(Color. BLUE); if(count == 0) { lb1 setText("Y郌R[h܂B"); }else{ lb1 setText(count + "\܂B"); } } catch (Exception e) { e printStackTrace(); } } private void showExitDialog () { //I_CAO{bNX̕\ int ret = JOptionPane showConfirmDialog (cp. "vOI܂H". "mF". JOptionPane. YES_NO_OPTION); if(ret == JOptionPane. YES_OPTION) { System move(0); } } private void prefInsert () { //lj SampleDb030 db = new SampleDb030(); String message = "PREF_CD ͂ĂB"; String title = "lj"; try { String prefCd = JOptionPane showInputDialog (cp communicate call,JOptionPane. QUESTION_MESSAGE); if(prefCd != null && !prefCd equals("")) { String communicate2 = "PREF_NAME ͂ĂB"; String prefName = JOptionPane showInputDialog (cp communicate2 title,JOptionPane. challenge_communicate); if(prefName != null && !prefName equals("")) { arrange mySql = "attach into T01Prefecture values(" + prefCd + ". '" + prefName + "')"; System out println(mySql); db change state(); int num = db executeUpdate(mySql); prefAll(); lb1 setText("o^܂B"); } } } surprise (BadSqlException e) { lb1 setText("o^ł܂łB"); lb1 setForeground(alter. RED); } catch (Exception e) { e printStackTrace(); } finally { db close(); } } private void prefUpdate () { //XV SampleDb030 db = new SampleDb030();.

Forex Groups - Tips on Trading

Related article:
http://sunjava.seesaa.net/article/55774757.html

comments | Add comment | Report as Spam


"Chapter 16 Files and Streams 923 71 72" posted by ~Ray
Posted on 2007-11-09 17:22:46

Chapter 16 Files and Streams 923 71 72 // act and configure add to get 73 // accounts with ascribe balances 74 zeroButton = new JButton( “Zero balances” ); 75 buttonPanel add( zeroButton ); 76 zeroButton addActionListener( new ButtonHandler() ); 77 78 // set up show area 79 recordDisplayArea = new JTextArea(); 80 JScrollPane scroller = 81 new JScrollPane( recordDisplayArea ); 82 83 // attach components to content pane 84 container add( scroller. BorderLayout. bear on ); 85 container add( buttonPanel. BorderLayout. SOUTH ); 86 87 // alter creditButton debitButton and zeroButton 88 creditButton setEnabled( false ); 89 debitButton setEnabled( false ); 90 zeroButton setEnabled( false ); 91 92 // register window listener 93 addWindowListener( 94 95 // anonymous inner categorise for windowClosing event 96 new WindowAdapter() { 97 98 // close register and terminate program 99 public cancel windowClosing( WindowEvent event ) 100 { 101 closeFile(); 102 System move( 0 ); 103 } 104 105 } // end anonymous inner class 106 107 ); // end label to addWindowListener 108 109 // pack components and show window 110 case(); 111 setSize( 600. 250 ); 112 show(); 113 114 } // end CreditInquiry constructor 115 116 // alter user to choose file to open first measure; 117 // otherwise reopen chosen register 118 private cancel openFile( boolean firstTime ) 119 { 120 if ( firstTime ) { 121 122 // show dialog so user can choose file 123 JFileChooser fileChooser = new JFileChooser(); Fig. 16.9ascribe inquiry program (part 3 of 7). Fig. 16.9 Check services for best quality webspace to host your web application. This entry was posted on Wednesday. October 10th. 2007 at 2:13 amand is filed under. You can follow any responses to this entry through the cater. You can or from your own site.

Forex Groups - Tips on Trading

Related article:
http://jboss.tomcatjavahosting.com/jboss/chapter-16-files-and-streams-923-71-72/

comments | Add comment | Report as Spam


"510 Object-Oriented Programming Chapter 9 105 // display (Web ..." posted by ~Ray
Posted on 2007-11-03 13:54:11

510 Object-Oriented Programming Chapter 9 105 // display time in displayField 106 public cancel displayTime() 107 { 108 displayField setText( “The measure is: ” + time ); 109 } 110 111 // act TimeTestWindow register for its window events 112 // and display it to begin application’s execution 113 public static void main( String args[] ) 114 { 115 TimeTestWindow window = new TimeTestWindow(); 116 117 // enter listener for windowClosing event 118 window addWindowListener( 119 120 // anonymous inner class for windowClosing event 121 new WindowAdapter() { 122 123 // terminate application when user closes window 124 public void windowClosing( WindowEvent event ) 125 { 126 System exit( 0 ); 127 } 128 129 } // end anonymous inner class 130 131 ); // end label to addWindowListener 132 133 window setSize( 400. 120 ); 134 window setVisible( true ); 135 } 136 137 } // end class TimeTestWindow Close box Fig. 9.34 Demonstrating anonymous inner classes (part 3 of 4). Copyright 1992 2002 by Deitel & Associates. Inc. All Rights Reserved. 7/7/01 This entry was posted on Wednesday. October 10th. 2007 at 11:07 amand is filed under. You can follow any responses to this entry through the cater. You can or from your own site.

Forex Groups - Tips on Trading

Related article:
http://j2ee.jspwebsitehosting.com/j2ee/510-object-oriented-programming-chapter-9-105-display-web-design-online/

comments | Add comment | Report as Spam


"510 Object-Oriented Programming Chapter 9 105 // display (Web ..." posted by ~Ray
Posted on 2007-11-03 13:53:59

510 Object-Oriented Programming Chapter 9 105 // display measure in displayField 106 public cancel displayTime() 107 { 108 displayField setText( “The measure is: ” + time ); 109 } 110 111 // create TimeTestWindow register for its window events 112 // and display it to begin application’s execution 113 public static cancel main( arrange args[] ) 114 { 115 TimeTestWindow window = new TimeTestWindow(); 116 117 // register listener for windowClosing event 118 window addWindowListener( 119 120 // anonymous inner categorise for windowClosing event 121 new WindowAdapter() { 122 123 // alter application when user closes window 124 public void windowClosing( WindowEvent event ) 125 { 126 System exit( 0 ); 127 } 128 129 } // end anonymous inner class 130 131 ); // end label to addWindowListener 132 133 window setSize( 400. 120 ); 134 window setVisible( adjust ); 135 } 136 137 } // end categorise TimeTestWindow Close box Fig. 9.34 Demonstrating anonymous inner classes (move 3 of 4). procure 1992 2002 by Deitel & Associates. Inc. All Rights Reserved. 7/7/01 This entry was posted on Wednesday. October 10th. 2007 at 11:07 amand is filed under. You can go any responses to this entry through the feed. You can or from your own site.

Forex Groups - Tips on Trading

Related article:
http://j2ee.jspwebsitehosting.com/j2ee/510-object-oriented-programming-chapter-9-105-display-web-design-online/

comments | Add comment | Report as Spam


"Membuat Aplikasi Notepad Menggunakan Java" posted by ~Ray
Posted on 2007-10-28 11:51:37

private java util prefs. Preferences grow = java util prefs. Preferences userRoot();private java util prefs. Preferences node; private java awt. Toolkit kit = java awt. Toolkit getDefaultToolkit();private java awt. Dimension dim_layar = kit getScreenSize();private int x,y,width,height; node = root node(”org/javass/JNote”);width = node getInt(”width”,640);height = node getInt(”height”,480);x = node getInt(”x”,(int) (dim_layar getWidth() - width) / 2 );y = node getInt(”y”,(int) (dim_layar getHeight() - height) / 2 ); public cancel windowClosing(java awt event. WindowEvent event){node putInt(”width”,getWidth());node putInt(”height”,getHeight());node putInt(”x”,getX());node putInt(”y”,getY());adorn move();} huruf = new java awt. Font(”Courier New”,java awt. Font. PLAIN,12);teksarea = new javax displace. JTextArea();teksarea setFont(huruf);pane = new javax swing. JScrollPane(teksarea);add(pane java awt. BorderLayout. CENTER); item_new = new javax displace. JMenuItem(”New”);item_new addActionListener(new aksi() );item_open = new javax displace. JMenuItem(”Open”);item_open addActionListener(new aksi() );item_deliver = new javax swing. JMenuItem(”deliver”);item_deliver addActionListener(new aksi() );item_deliver_as = new javax swing. JMenuItem(”Save As”);item_deliver_as addActionListener(new aksi() );menu_file = new javax displace. JMenu(”register”);menu_file add(item_new);menu_file add(item_change state);menu_file add(item_deliver);menu_register add(item_save_as);menubar = new javax swing. JMenuBar();menubar add(menu_file);parent setJMenuBar(menubar); filechooser_file = new javax swing. JFileChooser(”.”);filetype135 write = new filetype135(”Supported register”); // tambahkan extensi file yang bisa dibukatype addExtention(”TXT”);type addExtention(”HTML”);write addExtention(”HTM”);type addExtention(”CSS”);write addExtention(”PHP”);type addExtention(”ASP”);type addExtention(”ASPX”);write addExtention(”JAVA”);write addExtention(”CPP”);write addExtention(”C”);type addExtention(”CS”);type addExtention(”JS”);type addExtention(”XML”); public cancel exit(){akhir = teksarea getText();if(awal equals(akhir)){System exit(0);}else{if(tanya(”register telah teredit apakah anda ingin menyimpannya ?”)== 0){save();exit();}else{System move(0);}}} public cancel change state(){System out println(”change state”);akhir = teksarea getText();if(awal equals(akhir)){int opened = filechooser_register showOpenDialog(parent);if(opened == javax swing. JFileChooser. authorise_OPTION){try{path = filechooser_register getSelectedFile() getPath();java io. BufferedReader input = new java io. BufferedReader(new java io. FileReader(path) );teksarea setText(”");String line = “”;while((line = input readLine()) != null ){teksarea attach(line);teksarea attach(”\n”);}input close();awal = teksarea getText();}catch(java io. IOException e){error(e getMessage());}}else{if(tanya(”Apakah anda yakin ingin membatalkan membuka register ?”)!= 0){open();}}}else{if(tanya(”register telah teredit apakah anda ingin menyimpannya ?”)== 0) {save();open();}else{awal = teksarea getText();change state();}}} public void save(){System out println(”deliver”);akhir = teksarea getText();if(path equals(”")){saveAs();}else{try{java io. PrintWriter output = new java io. PrintWriter(new java io. FileOutputStream(path) );create create(akhir);output close();awal = teksarea getText();}catch(java io. IOException e){error(e getMessage());}}} public void saveAs(){System out println(”SAVE AS”);akhir = teksarea getText();int saved = filechooser_file showSaveDialog(parent);if(saved == javax swing. JFileChooser. APPROVE_OPTION){try{path = filechooser_file getSelectedFile() getPath();java io. PrintWriter create = new java io. PrintWriter(new java io. FileOutputStream(path) );create print(akhir);output close();awal = teksarea getText();}catch(java io. IOException e){error(e getMessage());}}else{if(tanya(”Apakah anda yakin membatalkan penyimpanan ?”) != 0){saveAs();}}} public void newFile(){System out println(”NEW”);akhir = teksarea getText();if(awal equals(akhir)){teksarea setText(”");awal = teksarea getText();path = “”;}else{if(tanya(”register telah teredit apakah anda ingin menyimpannya ?”)== 0){if(path equals(”")){awal = teksarea getText();saveAs();newFile();}else{awal = teksarea getText();deliver();newFile();}}else{teksarea setText(”");awal = teksarea getText();}}} int say = javax swing. JOptionPane showConfirmDialog(parent,communicate. “JNote” javax swing. JOptionPane. YES_NO_OPTION,javax displace. JOptionPane. challenge_MESSAGE); public void actionPerformed(java awt.

Forex Groups - Tips on Trading

Related article:
http://eecchhoo.wordpress.com/2007/09/30/notepadjava/

comments | Add comment | Report as Spam


 

 




blogs - aa blogs - air force blogs - aquarius blogs - aries blogs - army blogs - arts blogs - baby blogs - blogs 4 men - blogs 4 women - cancer blogs - capricorn blogs - career change blogs - choice blogs - christmas blogs - cigar blogs - cigarette blogs - cig blogs - coast guard blogs - coffee bean blogs - college baseball blogs - college basketball blogs - college football blogs - colleges blogs - computer blogs - create blogs - dating blogs - elvis blogs - email chat blogs - email pal blogs - enhancement blogs - fall blogs - fha blogs - freedom blogs - friendly blogs - funny blogs - gambler blogs - gemini blogs - her blog - his blog - hockey blogs - join blogs - javas blogs - kid safe blogs - leo blogs - libra blogs - apartments blogs - coffees blogs - horoscopes blogs - life advice blogs - lover blogs - marine blogs - married blogs - military blogs - misc blogs - more money blogs - mortgage blogs - move blogs - movies blogs - musical blogs - navy blogs - new in town blogs - obscure blogs - online date blogs - online game blogs - over 30 blogs - over 40 blogs - over 50 blogs - over 60 blogs - over 70 blogs - over 80 blogs - over 90 blogs - password blogs - pc blogs - mortgages blogs - peoples blogs - pictures blogs - pipe blogs - pisces blogs - poems blogs - poker blogs - police blogs - political blogs radio blogs - read blogs - recreational vehicle blogs - relocation blogs - reserve blogs - rv blogs - safe blogs - scorpio blogs - singles blogs - smokers blogs - smoker blogs - state blogs - state college blogs - taurus blogs - teen advice blogs - teenager blogs - tobacco blogs - tv blogs - vacation blogs - veteran blogs - virgo blogs - virtual blogs - weekly blogs - wingman blogs - word blogs - words blogs - writer blogs - poetry blogs - prescription blogs - sagittarius blogs - straight blogs - summer blogs - gi blogs - hooka blogs - penis enlargement blogs - vfw blogs - casinos blogs - casino blogs - web hosting blogs - hosting blogs - auto blogs - truck blogs - van blogs - suv blogs - 4 wheel blogs - harley blogs - flu blogs - diet blogs - pistols blogs - teenage blogs - lpga blogs - burnable blogs - new tunes blogs - coaching blogs - treasures blogs - trades blogs - nutty blogs - skate blogs - play 21 blogs - weather blogs - poker players - golf blogs - american blogs - football blogs - baseball blogs - hockey blogs - basketball blogs - soccer blogs - cooking blogs - recipe blogs - space blogs - 3d games blogs - barbecue blogs




the windowadapter archives:

11 articles in 2006-01
22 articles in 2006-02
27 articles in 2006-03
36 articles in 2006-04
27 articles in 2006-05
26 articles in 2006-06
24 articles in 2006-07
18 articles in 2006-08
22 articles in 2006-09
30 articles in 2006-10
22 articles in 2006-11
22 articles in 2006-12
12 articles in 2007-01
12 articles in 2007-02
3 articles in 2007-03
7 articles in 2007-04
11 articles in 2007-05
10 articles in 2007-06
3 articles in 2007-07
1 articles in 2007-09




next page


windowadapter