QuaQaJBAL在Mac OS X上的JAVA Swing应用程序中显示一个表单

・3 分钟阅读

Java例子程序

为此,我创建了以下Java例子应用程序,以便了解Quaqua JSheet实现的内容,我先在这里分享Java源代码,然后描述它的作用:

package com.devdaily.quaqua.test;
import java.awt.*;
import javax.swing.*;
import ch.randelshofer.quaqua.JSheet;
import ch.randelshofer.quaqua.SheetEvent;
import ch.randelshofer.quaqua.SheetListener;
/**
 * A free Java program to test and demonstrate the Quaqua JSheet
 * implementation.
 * Created by Alvin Alexander, devdaily.com.
 */
public class QuaquaTest
{
 public static void main(String[] args)
 throws Exception
 {
 System.setProperty(\"Quaqua.tabLayoutPolicy\",\"wrap\");
 UIManager.setLookAndFeel(\"ch.randelshofer.quaqua.QuaquaLookAndFeel\");
 new QuaquaTest();
 }
 public QuaquaTest()
 {
 SwingUtilities.invokeLater(new Runnable()
 {
 public void run()
 {
 JFrame editorFrame = new JFrame(\"Java Mac OS X Quaqua Test\");
 constructAndDisplayJFrame(editorFrame);
 displayJSheet(editorFrame);
 }
 });
 }
 private void constructAndDisplayJFrame(JFrame editorFrame)
 {
 editorFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
 editorFrame.setPreferredSize(new Dimension(300, 185));
 editorFrame.pack();
 editorFrame.setLocationRelativeTo(null);
 editorFrame.setVisible(true);
 }
 /**
 * Displays a JSheet using the Quaqua framework.
 * This code was just copied from the Quaqua help pages.
 */
 private void displayJSheet(final JFrame editorFrame)
 {
 JOptionPane pane = new JOptionPane(
\"<html>\"+UIManager.getString(\"OptionPane.css\")+
\"<b>Do you want to save changes to this document<br>\"+
\"before closing?</b><p>\"+
\"If you don\'t save, your changes will be lost.\",
 JOptionPane.WARNING_MESSAGE
 );
 Object[] options = {\"Save\",\"Cancel\",\"Don\'t Save\" };
 pane.setOptions(options);
 pane.setInitialValue(options[0]);
 pane.putClientProperty(\"Quaqua.OptionPane.destructiveOption\", new Integer(2));
 JSheet.showSheet(pane, editorFrame, new SheetListener() {
 public void optionSelected(SheetEvent evt) {
 Object value = evt.getValue();
 if (value == null || value.equals(\"Cancel\")) {
 editorFrame.setEnabled(true);
 } else if (value.equals(\"Don\'t Save\")) {
 editorFrame.dispose();
 } else if (value.equals(\"Save\")) {
 //saveChanges();
 }
 }
 });
 }
}

讨论

此程序执行以下操作:

  1. main方法中做一些Quaqua设置工作,
  2. 创建空的JFrame
  3. 用Quaqua帮助文档中使用一些源代码去创建joptionPane,然后用Quaqua JSheet显示该JOptionPane ,

如果你在自己的系统上编译,并且运行此程序,你将看到所有这些都在程序运行后立即发生。也就是说,JFrame将被显示,然后JSheet将立即显示。

Xn_warm profile image