博文

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......

阅读全文(7708) | 评论:0

JRadioButton用法(2005-09-18 17:22:00)

摘要:import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.FlowLayout;
public class JRadioButtonDemo
{
 public static void main(String[] args)
 {
  
  JRadioButton red, white, cyan;
  red = new JRadioButton ("red");
  white = new JRadioButton ("white");
  cyan = new JRadioButton ("cyan");
 
  ButtonGroup group = new ButtonGroup ();
  group.add (red);
  group.add (white);
  group.add (cyan);
  
  JPanel panel = new JPanel (new FlowLayout (FlowLayout.CENTER, 1, 0));
  panel.setBackground (Color.white);
  panel.setPreferredSize (new Dimension (200,50));
  panel.add (red);
  panel.add (white);
  panel.add (cyan);......

阅读全文(5041) | 评论:0

JProgressBar用法(2005-09-18 17:21:00)

摘要:import java.awt.Color;
import javax.swing.JProgressBar;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.FlowLayout; public class JProgressBarDemo
{
 public static void main (String[] args)
 {
  JProgressBar progressBar = new JProgressBar (JProgressBar.VERTICAL, 10, 100);
  progressBar.setBackground (Color.white);
  progressBar.setForeground (Color.red);
  progressBar.setValue (40);
  progressBar.setString ("progressBar");
  
  
  JPanel panel = new JPanel (new FlowLayout (FlowLayout.LEFT));
  panel.setPreferredSize (new Dimension (600,400));
  panel.add (progressBar);
  
  
  JFrame frame = new JFrame ("JProgressBarDemo");
  frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  frame.setContentPane (panel);

阅读全文(7117) | 评论:0

JOptionPane用法(2005-09-17 01:07:00)

摘要:package hu.demos;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.Icon;
public class JOptionPaneDemo
{
 public static void main(String[] args)
 {
  Icon icon = new ImageIcon("QQ.png");
  int confirmMessage;
  Object[] possibleValues = {"First", "Second", "Third"};
  Object inputMessage;
  
  //-----------------------------------------------------------------
  // Usage:
  // method: static String/Object | showInputDialog(Xxx)
  //-----------------------------------------------------------------  
  
  /*1
  showInputDialog(Object message);
  */
//  inputMessage = JOptionPane.showInputDialog ("Input a Integer:");
  
  
  
  /*2
  showInputDialog(Object mes......

阅读全文(12973) | 评论:3

JMenuBar用法(2005-09-17 01:01:00)

摘要://JMenu 继承自JMenuItem,它们都在javax.swing包中,都实现了Accessible, MenuElement 接口
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.MenuShortcut; public class JMenuBarDemo
{
 public static void main (String[] args)
 {
  //try{javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());}catch(Exception e){}
  JPanel panel = new JPanel ();
  panel.setBackground (Color.white);
  panel.setPreferredSize (new Dimension (600,400));
  //JMenu 有箭头(除了顶层的),可以添加JMenu和JMenuItem;
  //JMenuItem 无箭头,不可添加其他菜单项
  JMenu file, edit, search, item, view, format, macro, advance, windows, help;
  file = new JMenu ("File");
  edit = new JMenu ("Edit");
  search = new ......

阅读全文(6385) | 评论:0

JList用法(2005-09-17 00:59:00)

摘要:import javax.swing.JFrame;
import javax.swing.JSplitPane;
import javax.swing.JLabel;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Color;
import javax.swing.JList;
import javax.swing.BorderFactory; public class JListDemo
{
 public static void main(String[] args)
 {
  String[] names = {"孙中山", "袁世凯", "毛泽东", "蒋介石", "邓小平", "天安门"};
  JList list = new JList (names);
  list.setBorder (BorderFactory.createEtchedBorder());
  list.setFixedCellHeight (30);//设置每个选项的高度
  list.setFixedCellWidth (70);//设置每个选项的宽度,一般不需要
  list.setDragEnabled (true);
  list.setBackground (Color.cyan);
  list.setForeground (Color.red);
  list.setSelectionBackground (Color.white);
  list.setSelectionForeground (Color.black);
  list.setLayoutOrientation (JList.HORIZONTAL_WRAP);
 &......

阅读全文(8052) | 评论:0

JFrame用法(2005-09-17 00:58:00)

摘要:import java.awt.*;
import javax.swing.*; public class JFrameDemo extends Frame
{
 public static void main(String[] args)
 {
  JFrameDemo frame = new JFrameDemo ("My Frame");
  frame.setSize(200,200);
  frame.setBackground(Color.red);
  frame.setLayout(null);
  frame.setVisible(true);
  Panel panel = new Panel();
  panel.setSize(100, 100);
  panel.setBackground(Color.yellow);
  frame.add(panel);
  //frame.show();
 }
 
 public JFrameDemo (String str)
 {
  super(str);
 }
}......

阅读全文(4594) | 评论:3

JComboBox用法(2005-09-17 00:57:00)

摘要://组合框的选项是对象,不一定是字符串,比如可以显示图象,但最好不要将字符串和图象混合了放在一个组合框里 import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JComboBox;
import javax.swing.UIManager;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.ImageIcon; public class JComboBoxDemo
{
 public static void main(String[] args)
 {
  try {UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName ());}catch(Exception e){}
  String[] names = {"孙中山", "袁世凯", "毛泽东", "蒋介石", "邓小平", "天安 门"};
  MyBox equals = new MyBox (names);
  equals.addItem ("游神");
  equals.addItem ("猪头");
  
  MyBox images = new MyBox ();
  images.addItem (new ImageIcon ("Image//QQ.png"));
  images.addItem (new ImageIcon ("Image//fairy.gif"));
  
  JPanel panel = new JPanel(new FlowLayout (FlowLayout.CENTER, 0, 1));......

阅读全文(8946) | 评论:1

JColorChooser用法(2005-09-17 00:55:00)

摘要:import java.awt.Dimension;
import javax.swing.JColorChooser;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import java.awt.FlowLayout; public class JColorChooserDemo implements ActionListener
{
 public static void main(String[] args)
 {
  JFrame frame = new JFrame ("JColorChooserDemo");
  frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  MyPanel panel = new MyPanel();
  frame.getContentPane ().add (panel);
  frame.pack();
  frame.show();
 }
  
 public void actionPerformed(ActionEvent e)
 {
 }
} class MyPanel extends JPanel implements ActionListener
{
 private JButton button, rgb, red, green, blue;
 private Color color = new Color (0, 0, 0);
 public MyPane......

阅读全文(4830) | 评论:0

IOStream用法(2005-09-16 19:03:00)

摘要:/*
I/O流的层次
 1.字节流 2.字符流 3.对象流 4.其它  详细介绍:
---------------------------------------
1.字节流:  从InputStream和OutputStream派生出来的一系列类。这类流以字节(byte)为基本处理单位。
 ◇ InputStream、OutputStream
 ◇ FileInputStream、FileOutputStream
 ◇ PipedInputStream、PipedOutputStream
 ◇ ByteArrayInputStream、ByteArrayOutputStream
 ◇ FilterInputStream、FilterOutputStream
 ◇ DataInputStream、DataOutputStream
 ◇ BufferedInputStream、BufferedOutputStream
---------------------------------------
InputStream 和OutputStream InputStream 和OutputStream 是其他字节流的父类,他是一个抽象类,各有一个抽象方法:
abstract int read()和abstract write(int b);  InputStream:   ◇ 从流中读取数据:    int read( ); //读取一个字节,返回值为所读的字节    int read( byte b[ ] ); //读取多个字节,放置到字节数组b中,通常
        //读取的字节数量为b的长度,返回值为实际
        //读取的字节的数量    ......

阅读全文(5470) | 评论:3