joptionpane java_Java JOptionPane
Java JOptionPane
1 Java JOptionPane的介紹
JOptionPane類用于提供標(biāo)準(zhǔn)對(duì)話框,例如消息對(duì)話框,確認(rèn)對(duì)話框和輸入對(duì)話框。這些對(duì)話框用于顯示信息或從用戶那里獲取輸入。JOptionPane類繼承了JComponent類。
2?Java JOptionPane的聲明
public class JOptionPane extends JComponent implements Accessible
3?Java JOptionPane的構(gòu)造方法
構(gòu)造方法
描述
JOptionPane()
用于創(chuàng)建帶有測(cè)試消息的JOptionPane。
JOptionPane(Object message)
用于創(chuàng)建JOptionPane的實(shí)例以顯示消息。
JOptionPane(Object message, int messageType
用于創(chuàng)建JOptionPane的實(shí)例,以顯示具有指定消息類型和默認(rèn)選項(xiàng)的消息。
4?Java JOptionPane的方法
方法
描述
JDialog createDialog(String title)
用于創(chuàng)建和返回帶有指定標(biāo)題的新的無父母JDialog。
static void showMessageDialog(Component parentComponent, Object message)
用于創(chuàng)建標(biāo)題為“消息”的信息消息對(duì)話框。
static void showMessageDialog(Component parentComponent, Object message, String title, int messageType)
用于創(chuàng)建具有給定標(biāo)題和messageType的消息對(duì)話框。
static int showConfirmDialog(Component parentComponent, Object message)
用于創(chuàng)建帶有選項(xiàng)“是”,“否”和“取消”的對(duì)話框。標(biāo)題,選擇一個(gè)選項(xiàng)。
static String showInputDialog(Component parentComponent, Object message)
用于顯示一個(gè)問題消息對(duì)話框,要求從以parentComponent為父的用戶輸入。
void setInputValue(Object newValue)
用于設(shè)置用戶選擇或輸入的輸入值。
5?Java JOptionPane的案例1
package com.yiidian;
/**
* 一點(diǎn)教程網(wǎng): http://www.yiidian.com
*/
import javax.swing.*;
public class OptionPaneExample {
JFrame f;
OptionPaneExample(){
f=new JFrame();
JOptionPane.showMessageDialog(f,"你好, 歡迎訪問www.yiidian.com");
}
public static void main(String[] args) {
new OptionPaneExample();
}
}
輸出結(jié)果為:
6?Java JOptionPane的案例2
package com.yiidian;
/**
* 一點(diǎn)教程網(wǎng): http://www.yiidian.com
*/
import javax.swing.*;
public class OptionPaneExample {
JFrame f;
OptionPaneExample(){
f=new JFrame();
JOptionPane.showMessageDialog(f,"更新成功","提示框",JOptionPane.WARNING_MESSAGE);
}
public static void main(String[] args) {
new OptionPaneExample();
}
}
輸出結(jié)果為:
7?Java JOptionPane的案例3
package com.yiidian;
/**
* 一點(diǎn)教程網(wǎng): http://www.yiidian.com
*/
import javax.swing.*;
public class OptionPaneExample {
JFrame f;
OptionPaneExample(){
f=new JFrame();
String name=JOptionPane.showInputDialog(f,"請(qǐng)輸入名稱:");
}
public static void main(String[] args) {
new OptionPaneExample();
}
}
輸出結(jié)果為:
8?Java JOptionPane的案例4
package com.yiidian;
import javax.swing.*;
import java.awt.event.*;
public class OptionPaneExample extends WindowAdapter{
JFrame f;
OptionPaneExample(){
f=new JFrame();
f.addWindowListener(this);
f.setSize(300, 300);
f.setLayout(null);
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
f.setVisible(true);
}
public void windowClosing(WindowEvent e) {
int a=JOptionPane.showConfirmDialog(f,"確定刪除么?");
if(a==JOptionPane.YES_OPTION){
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
public static void main(String[] args) {
new OptionPaneExample();
}
}
輸出結(jié)果為:
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的joptionpane java_Java JOptionPane的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cancase vector_基于Vec
- 下一篇: 小米叶脉冷泵散热效果明显 网友:别把骁龙