miui9开发版刷回稳定版:两个关于java gui的简单问题

来源:百度文库 编辑:神马品牌网 时间:2024/05/06 16:26:15
package visualtest4;

import java.awt.BorderLayout;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;

public class MainForm extends JFrame {

private JPanel jContentPane = null;
private JButton jButtonShowoff = null;
/**
* This method initializes jButtonShowoff
*
* @return javax.swing.JButton
*/
private JButton getJButtonShowoff() {
if (jButtonShowoff == null) {
jButtonShowoff = new JButton();
jButtonShowoff.setBounds(new java.awt.Rectangle(51,98,139,33));
jButtonShowoff.setText("Showoff");
jButtonShowoff.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
showoff();
}
});
}
return jButtonShowoff;
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
java.awt.EventQueue.invokeLater(new Runnable(){
public void run(){
new MainForm().setVisible(true);
}
});
}

/**
* This is the default constructor
*/
public MainForm() {
super();
initialize();
}

/**
* This method initializes this
*
* @return void
*/

private void showoff(){
int selection=JOptionPane.showConfirmDialog(this,
"Are you sure to quit?","Warning",
JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE);
if(selection==JOptionPane.OK_OPTION){
System.exit(0);
}
}

private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}

/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJButtonShowoff(), null);
}
return jContentPane;
}

}
两个问题:
1 JOptionPane.showConfirmDialog函数中的各个参数都有什么意义?
2 java.awt.EventQueue.invokeLater(new Runnable(){
public void run(){
new MainForm().setVisible(true);}});
这一语句的作用是什么?
菜鸟上路,麻烦高人指教,剩下的分数不多了,只够十分,谢谢帮忙。
还有一个问题,eclipse中有没有像msdn这样的帮助系统啊?

public static int showConfirmDialog(Component parentComponent,
Object message,
String title,
int optionType)
throws HeadlessException
Parameters:
parentComponent - determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is used
确定要显示的对话框的父Frame;如果是空,或父容器没有Frame,将会使用一个默认的Frame
message - the Object to display要显示的信息
title - the title string for the dialog对话框标题
optionType - an int designating the options available on the dialog: YES_NO_OPTION, or YES_NO_CANCEL_OPTION
风格,两种可选
invokeLater():要求在事件派发线程中执行某些代码。这个方法会立即返回,不会等待代码执行完毕
在java的主线程(Main Thread)中是使用事务的方式来处理事件的,主线程中有一个事件队列,当你所要做的动作将被放到主线程中处理而又不需要马上处理(或不想中断目前正在执行的事务),则可以使用InvokeLater方法将该事务放到事件队列的最后。让主线程自行执行。
使用InvokeLater不知道在什么时候会执行该事务,但好处是不会和其它事务起冲突。Swing中的重绘也是用InvokeLater来实现的