博文

java中的全屏幕模式(2006-10-09 16:21:00)

摘要:什么时候会用到全屏幕模式? 也许用到的机会很少,但JDK还是为我们提供了这个的功能。像许多软件中的打印预览功能,还有某些文本编辑器中为了获得更大的编辑画面,也用到了全屏幕模式,如果你有兴趣写一个像ACDSee这样的软件,使用全屏幕模式可以让用户看到更大的图片画面。 如何使用全屏幕模式? 关键是java.awt.*里面的两个与显示设备有关的类:GraphicsEnvironment和GraphicsDevice。 GraphicsEnvironment为Java应用程序提供了特定平台的 GraphicsDevice 对象和 Font 对象集合。这些GraphicsDevice可以是各种本机和远端机器的资源,如屏幕、打印机或者是Image Buffer,甚至是Graphics2D绘图方法的目标对象。 而GraphicsDevice就是指特定的图形环境了,如屏幕和打印设备等。这样,我们就可以用GraphicsDevice来操纵屏幕了。GraphicsDevice提供的setFullScreenWindow()方法就是设置全屏幕用的。 由于GraphicsEnvironment的构造器是受保护的(protected),我们不能直接构造一个 GraphicsEnvironment对象来获得GraphicsDevice对象。幸好它提供了getLocalGraphicsEnvironment()方法,用来获得一个GraphicsEnvironment实例: GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 有了GraphicsEnvironment可以调用getDefaultScreenDevice方法获得当前的屏幕设备了: GraphicsDevice gd = ge.getDefaultScreenDevice(); 自己动手体验一下 有了上面的简介,写一个实例来体验一下吧: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FullScreenTest {    public static void main(String[] ......

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

JSplitPane(2006-05-21 09:44: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方法中的值,           //此处为200/500,大概在中间靠左   JFrame frame = new ......

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

JTable(2006-05-21 09:37: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", "学生", "寄生中", "未婚", "没"},     {"eee", "女", "江苏南京", "13645181705", "xx/xx/1985", "家教", "未知", "未婚", "好象没"......

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

JTablePanel(2006-05-21 09:30: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 vgap)  //new GridLayout () or new GridLayout (int rows, int cols) new GridLayout (int rows, int ......

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

JFrame[转载](2006-05-21 09:16: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); }}   谁都会写但这可以说是最最原始的......GUI的HelloWorld吧!......

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

JColorChooser[转载](2006-05-21 09:13: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 MyPanel() {  button = new JButton ("Get Color");  rgb = new JButton ("RGB: "); &nb......

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

关于Java中不调用Applet类播放声音的方法(2006-04-16 17:00:00)

摘要:try {        // From file        AudioInputStream stream = AudioSystem.getAudioInputStream(new File("audiofile"));            // From URL        stream = AudioSystem.getAudioInputStream(new URL("http://hostname/audiofile"));            // At present, ALAW and ULAW encodings must be converted        // to PCM_SIGNED before it can be played        AudioFormat format = stream.getFormat();        if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {            format = new AudioFormat(                    AudioFormat.Encoding.PCM_......

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