博文
OutputStreamWriter用法(2005-09-22 17:21:00)
摘要:example2:OutputStreamWriterDemo.java
/************************************************************************
以FileOutputStreamDemo.java为摸板,按回车后再按Ctrl+z结束输入,可输入中文
************************************************************************/
import java.io.*;
public class OutputStreamWriterDemo
{
public static void main(String[] args)throws IOException
{
try
{
InputStreamReader isr = new InputStreamReader (new FileInputStream (FileDescriptor.in));
OutputStreamWriter osw = new OutputStreamWriter (new FileOutputStream ("D://testfile//output.log"));
int is;
while ((is=isr.read()) != -1)osw.write(is);
isr.close();
osw.close();
}
catch(FileNotFoundException e)
{
System.out.println(e);
}
ca......
Layout用法(2005-09-22 17:20:00)
摘要:import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.ImageIcon;
import javax.swing.Box;
import javax.swing.SwingConstants;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JButton;
import java.awt.event.*;
public class LayoutDemo
{
public static void main(String[] args)
{
JFrame frame = new JFrame ("Layout Manager Demo");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JTabbedPane tp = new JTabbedPane();
tp.addTab ("Flow",new FlowPanel());
tp.addTab ("Border",new BorderPanel());
tp.addTab ("Grid",new GridPanel());
tp.addTab ("Box",new BoxPanel());
frame.se......
JTree用法(2005-09-22 17:20:00)
摘要:import java.awt.Dimension;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.BoxLayout;
import javax.swing.tree.TreePath;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
/*
JTree的构造函数:
JTree()
JTree(Hashtable value)
JTree(Object[] value)//只有这个构造函数可以创建多个根结点
JTree(TreeModel newModel)
JTree(TreeNode root)
JTree(TreeNode root, boolean asksAllowsChildren)
JTree(Vector value)
*/
public class JTreeDemo
{
public static void main (String[] args)
{
//构造函数:JTree()
JTree example1 = new JTree();
//构造函数:JTree(Object[] value)
Object[] letters= {"a", "b", "c", "d", "e"};
JTree example2 = new JTree (letters);
//构造函数:JTree(TreeNode root)(TreeNode空)
&nb......
JTextArea用法(2005-09-22 17:19:00)
摘要:import java.awt.Color;
import java.awt.Font;
import java.awt.Point;
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
public class JTextAreaDemo
{
public static void main(String[] args)
{
try{javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());}catch(Exception e){}
JTextArea ta = new JTextArea(20,20);
ta.setBorder (BorderFactory.createEmptyBorder (1,1,1,5));
ta.setColumns (0); ta.setRows (0);//相当于设置文本区组件的初始大小,并不是说一行只能写0个字符;
ta.setLineWrap (false);//设置为禁止自动换行,初始值为false.
ta.setTabSize (4);//设置制表符的大小为8个字符,初始值为4个字符
ta.setWrapStyleWord (true);
ta.setBackground (Color.white);//文本区背景
ta.setForeground (Color.red);//字体颜色
ta.setF......
JTable用法(2005-09-22 17:19:00)
摘要:import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.table.TableColumn;
public class JTableDemo
{
public static void main (String[] args)
{
/*
构造函数有很多下面先介绍几个:
JTable()
JTable(int numRows, int numColumns)
JTable(Object[][] rowData, Object[] columnNames)
*/
JTable example1 = new JTable ();//看不到但存在
JTable example2 = new JTable (8, 6);
final Object[] columnNames = {"姓名", "性别", "家庭地址",//列名最好用final修饰
"电话号码", "生日", "工作", "收入", "婚姻状况","恋爱状况"};
Object[][] rowData = {
{"ddd", "男", "江苏南京", "1378313210", "03/24/1985", "学生", "寄生中", "未婚", "没......
JTabbedPane用法(2005-09-22 17:18:00)
摘要:import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.BoxLayout;
import javax.swing.JTabbedPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.UIManager;
class TabPane extends JTabbedPane
{
JPanel panel1, panel2, panel3, panel4, panel5;
public TabPane ()
{
//super (a, b);
panel1 = new JPanel ();
panel1.add(new JButton());
panel2 = new JPanel (new BorderLayout());
panel3 = new JPanel (true);
panel4 = new JPanel (new GridLayout(2,3));
panel5 = new JPanel (new FlowLayout(FlowLayout.LEFT, 1, 0));
//以上是JPanel的四种构造方法
//窗体布局器有四种设置:
//new BorderLayout () or new BorderLayout (int hgap, int vg......
全面认识JAVA[转](2005-09-20 22:57:00)
摘要:
全面认识JAVA
作者:刘静 来自:沈阳银河网络教育中心
作SCJP培训已经有一段时间了,到我这学习的有在校的大学生,也有在职的开发人员。通常这些学员此前都对Java已有一些了解,但普遍对Java缺乏总体的认识。于是学员总是问,Java应该怎么学?Java能做什么?什么是Applet?什么是Servlet、Jsp、EJB?还有Webspere、Weblogic又是做什么的等等。之所以学员会有这些疑问,是因为大家普遍对Java相关概念听说的太多而了解的又相对少的缘故。
学通Java语言需要一个过程,所有Java相关的概念都会在学习的过程中逐渐变得清昕。这个过程的开始就是要先学会标准的Java技术(J2SE),然后是学Java的简单Web运用,然后分布式运用,再以后对Java的移动技术运用就很容易理解了。
以下是Java标准技术的一些要点:
一、Java的跨平台性,即一次编译到处运行
简单地说Java的跨平台性就是指,编译后的Java程序可直接在不同的平台上运行而不用重新编译,这一特性使得Java随着Web应用的普及而迅速普及起来。而Java的跨平台性是如何实现的呢?这就要理解Java虚拟机和字节码的概念。
实际上,编译后的Java代码并不是传统的二进制代码(如Windows下的.exe文件),而是Java字节码,这种字节码文件是不能直接在操作系统上执行的。要想在一个操作系统上运行一个Java程序必须有一个中间环节来负责将Java字节码解释成二进制码,这个中间环节就是Java虚拟机(简称JVM)。由于目前大多数操作系统已经实现了JVM,所以Java轻松实现跨平台性。
二、面象对象技术
Java全面支持面象对象技术,这体现在Class(类)是Java程序构成的基本单元,一个Java程序通常由许多Class组成,而且这些Class还会有一定的继承关系,Java支持Class的单继承,从而使类之间的继承关系更明确。继承的结果产生类的多态性,类的多态本质上讲就是可以用父类的引用访问继承类的实现(子类对象),类的这种多态性最终形成了组件对象模型的基础,即通过接口(父类)访问实现(子类)。
三、Java中的I/O操作
Java中以字......
JTabbeld用法(2005-09-18 17:23:00)
摘要:import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.BoxLayout;
import javax.swing.JTabbedPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.UIManager;
class TabPane extends JTabbedPane
{
JPanel panel1, panel2, panel3, panel4, panel5;
public TabPane ()
{
//super (a, b);
panel1 = new JPanel ();
panel1.add(new JButton());
panel2 = new JPanel (new BorderLayout());
panel3 = new JPanel (true);
panel4 = new JPanel (new GridLayout(2,3));
panel5 = new JPanel (new FlowLayout(FlowLayout.LEFT, 1, 0));
//以上是JPanel的四种构造方法
//窗体布局器有四种设置:
//new BorderLayout () or new BorderLayout (int hgap, int vg......
JSplitPane用法(2005-09-18 17:23:00)
摘要:import javax.swing.*;
import java.awt.Dimension;
public class JSplitPaneDemo
{
public static void main (String[] args)
{
JButton button = new JButton ("button");
JLabel label = new JLabel ("label");
JSplitPane splitPane = new JSplitPane ();
splitPane.setOneTouchExpandable (true);//是该分隔面板的分隔条显示出箭头
splitPane.setContinuousLayout (true);
splitPane.setPreferredSize (new Dimension (500,600));//设置大小
splitPane.setOrientation (JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent (button);//same as: splitPane.setTopComponent(button);
splitPane.setRightComponent (label);//same as: splitPane.setBottomComponent(label);
splitPane.setDividerSize (5);//设置分隔条的粗细
splitPane.setDividerLocation(200);//设置分隔条的位置,基于setPreferredSize方法中的值,
&nb......
JSlider用法(2005-09-18 17:22:00)
摘要:import java.awt.Color;
import javax.swing.JSlider;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.GridLayout;
public class JSliderDemo
{
public static void main (String[] args)
{
JSlider empty = new JSlider ();
JSlider age = new JSlider (JSlider.VERTICAL, 0, 150, 20);//设置方向,最小值,最大值,初始值
JSlider append = new JSlider ();
append.setOrientation (JSlider.HORIZONTAL);//设置方向
append.setMinimum (0);//设置最小值
append.setMaximum (100);//设置最大值
append.setMajorTickSpacing (20);//设置主标号间隔
append.setMinorTickSpacing (5);//设置辅标号间隔
append.setPaintLabels (true);//Default:false显示标签
append.setPaintTicks (true);//Default:false显示标号
append.setPaintTrack (true);//Determines whether the track is painted on the slider
appen......