Java点点滴滴

来源:互联网 发布:如何开通淘宝达人账号 编辑:程序博客网 时间:2024/06/18 06:17

(1)DefaultBoundedRangeModel model = new DefaultBoundedRangeModel();

        定义对象时就调用默认的构造函数实例化对象。

(2)public class ScrollBarExample extends JPanel {

             public ScrollBarExample() {

                  super(true);

          ...............

        super作用:

          javax.swing.JPanel.JPanel(boolean isDoubleBuffered)

     Creates a new JPanel with FlowLayout and the specified buffering strategy. If   isDoubleBuffered is true,the JPanel will use a double buffer.  参数:

           isDoubleBuffered a boolean, true for double-buffering, which uses additional  memory space to                      achieve fast, flicker-free updates;

 

(3)label.setText("    New Value is " + e.getValue() + "      ");

        void javax.swing.JLabel.setText(String text)

           Defines the single line of text this component will display. If the value of text is null or empty string, nothing is  displayed.The default value of this property is null.This is a JavaBeans bound property.

            参数:

            text另请参阅:

           setVerticalTextPosition

           setHorizontalTextPositionsetIcon

           @beaninfo

           preferred: true bound: true attribute: visualUpdate true description: Defines the single line of text this component will display.

(4)  public class ScrollBarExample extends JPanel {  //extends的是JPanel

              JLabel label;

              public ScrollBarExample() {

                   ..................

              }

              public static void main(String s[]) {

 

                       JFrame frame = new JFrame("Scroll Bar Example");                                                                    

                       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                       frame.setContentPane(new ScrollBarExample());//通过这句与上面的构造函数联系起来

                       frame.setSize(200,200);

                       frame.setVisible(true);

             }

          }

(5)   JTextArea对象可以直接add()入JFrame中;而JTextField必须放于JPanel中,不能直接add()入JFrame。

 

 

(6)  JFrame frame=new JFrame();

       ...........

       frame.pack();

 

       frame.pack()方法:

 

    依据放置的组件设定窗口的大小,使之正好能容纳所放置的所有组件,若pack()和setSize()同时出现于程序中,则放在后面的那个方法起作用,前面的方法被覆盖了 ,而不起作用!

 

(7)  frame.setContentPane(p);  等价于   frame.getContentPane().add(p);(此时两者皆是默认的CERTER)

 

      区别是f.setContentPane(p)只能是默认的位置:CENTER,而不能自由的调整

(8)接口(interface)是抽象方法和常量值的定义的集合;本质上,接口是特殊的抽象类,这种抽象类只包含常量和方法的定义,而没有变量和方法的实现。如:

    public interface runner{

          public static final int i=8;

          public int start();

          public void stop();

   }

(9)public void Register(int num) throws IoException{

          it(num<0)

              throw new IoException("人数为负数,不合理!");

          System.out.println("登记人数:"+Register);    

    }

若没有异常发生,执行System输出语句;若num<0发生异常时抛出异常信息“人数为负数,不合理!”,而不再执行System语句了。



原创粉丝点击