CalendarNote的总结

来源:互联网 发布:手机淘宝客链接转换器 编辑:程序博客网 时间:2024/06/16 19:23

1.JLabel文字显示位置

JLabel label = new JLable("Lable",SwingConstants.CENTER);//SwingConstants的静态变量还有LEFT/RIGHT/...

2.Calendar类,可以方便的得到现在以及其他时间段的各种形式的日期

Calendar calendar = Calendar.getInstance();//初始化,得到现在时间构成的Calendar类int year = calendar.get(calenday.YEAR);//得到目前年份,月、日类推

其static int MONTH用0~11代表1~12月,DAY_OF_WEEK用1~7代表周日~周六
3.JTextField按下回车键就会产生一个动作事件,设置其中文字的排列方式使用setHorizontalAlignment(int)

setHorizontalAlignment(int){}Valid keys are: JTextField.LEFT JTextField.CENTER JTextField.RIGHT JTextField.LEADING JTextField.TRAILING 

4.将字符保存在相应的对象中,方便读取和写入

hashtable = new Hashtable();file = new File("CalendarPad.txt");        if(!file.exists()) {            try {                FileOutputStream out = new FileOutputStream(file);//构建字符写入file文件中的流                ObjectOutputStream objectOut=new ObjectOutputStream(out);//构建一个对象输出流,将写入字符的流存入某对象中                objectOut.writeObject(hashtable);//设置流存入的对象                objectOut.close();//关闭流                out.close();//关闭流            }            catch(IOException e)            {            }        }//从输入流中提取用于保存字符的对象try {    FileInputStream inOne = new FileInputStream(file);    ObjectInputStream inTwo = new ObjectInputStream(inOne);    table = (Hashtable) inTwo.readObject();    inOne.close();    inTwo.close();}catch(Exception e){}

5.JSplitPane类可以为两个(且仅为两个)JPanel设置分割条,分隔条默认可调,可通过设置setEnable(false)来固定分隔条

public JSplitPane(int newOrientation,Component newLeftComponent,Component newRightComponent)Creates a new JSplitPane with the specified orientation and the specified components.newOrientation - JSplitPane.HORIZONTAL_SPLIT or JSplitPane.VERTICAL_SPLIT 分为水平和垂直

6.将焦点设定在JFrame上:

addWindowListener(new WindowAdapter() {    public void windowOpened(WindowEvent e)    {       requestFocus();    }});

7.Event的Object getSource()方法可以返回当前产生此事件的对象,但是类型是Object,如果需要对此对象(组件)进行操作则需要进行类型转换
8.Component的setCursor(Cursor c)可以当鼠标停留在调用组件上时进行光标变化

component.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));getPredefinedCursor(int)返回之前已定义好的Cursor
原创粉丝点击