在本篇博文中,本人要讲解一个在我们窗口编程中十分好用的小工具 —— Swing提示框:
Swing提示框
关于这个小工具,本人觉得没什么好讲的,所以就直接来给出代码:
package edu.youzg.util;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class ViewTool {
public static final String TITLE = "右转哥温馨提示";
public ViewTool() {
}
public static void showMessage(JFrame jfame, String message) {
JOptionPane.showMessageDialog(jfame, message, TITLE, JOptionPane.PLAIN_MESSAGE);
}
public static void showWarnning(JFrame jfame, String message) {
JOptionPane.showMessageDialog(jfame, message, TITLE, JOptionPane.WARNING_MESSAGE);
}
public static void showError(JFrame jfame, String message) {
JOptionPane.showMessageDialog(jfame, message, TITLE, JOptionPane.ERROR_MESSAGE);
}
public static int getChoice(JFrame jfame, String message, int optionType) {
return JOptionPane.showConfirmDialog(jfame, message, TITLE, optionType);
}
}
那么,本人来给出一个例子,来展示下这个类的使用:
package edu.youzg.test;
import javax.swing.JFrame;
import edu.youzg.util.ViewTool;
public class Test {
public static void main(String[] args) {
JFrame jf = new JFrame("右转哥测试窗口");
ViewTool.showMessage(jf, "konodioda");
}
}
那么,本人来展示下运行结果:
那么,关于本篇博文的所有内容,就讲解完毕了。
喜欢的同学请留下免费小👍和关注,谢谢!!!