java有没有象messagebox的东西 好像以前看见过 查了半天没查到 指点一下

jokerjava 2002-05-09 09:12:18
如题
谢谢
...全文
78 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jokerjava 2002-05-09
  • 打赏
  • 举报
回复
服务周到
谢了
skyyoung 2002-05-09
  • 打赏
  • 举报
回复
This example will show 2 radio buttons, one for english messages and buttons and the other one for french. Press the button to display a localized JOptionPane according to the radio button selected.
Create 2 properties files, one for english , one for french. [JOptionPane_en.properties]
Yes=Yes
No=No
Cancel=Cancel
SaveMsg=Do you want to save your data



[JOptionPane_fr.properties]
Yes=Oui
No=Non
Cancel=Annuler
SaveMsg=Voulez-vous sauvegarder vos donnees


Then import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;

public class MessageBoxExample extends JPanel
implements ActionListener {
JButton go;
AbstractButton button;
ButtonGroup group;
Locale locale;
String msg ;

public MessageBoxExample() {
group = new ButtonGroup();

locale = Locale.US; // default value
button = new JRadioButton("English", true);
button.setActionCommand("en");
button.addActionListener(this);
group.add(button);
add(button);

button = new JRadioButton("Francais");
button.setActionCommand("fr");
button.addActionListener(this);
group.add(button);
add(button);

go = new JButton("Do it");
go.addActionListener(this);
add(go);

locale = Locale.US;
}

public void setUILanguage() {
ResourceBundle rb;
rb = ResourceBundle.getBundle("JOptionPane", locale);

UIManager.put("OptionPane.yesButtonText", rb.getString("Yes"));
UIManager.put("OptionPane.noButtonText", rb.getString("No"));
UIManager.put("OptionPane.cancelButtonText", rb.getString("Cancel"));
msg = rb.getString("SaveMsg");
}

public void actionPerformed(ActionEvent e) {
int result;

if (e.getSource() instanceof JRadioButton) {
if (e.getActionCommand().equals("en"))
locale = Locale.US;
else
locale = Locale.FRANCE;
setUILanguage();
}
else {
// the button action
result = JOptionPane.showConfirmDialog(this,msg);
System.out.println(result);
}
}

public Dimension getPreferredSize(){
return new Dimension(200, 200);
}

public static void main(String s[]) {
JFrame frame = new JFrame("");
MessageBoxExample panel = new MessageBoxExample();
frame.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
frame.getContentPane().add(panel,"Center");
frame.setSize(panel.getPreferredSize());
frame.setVisible(true);
}
}

---------------
shmilu@sina.com
ezyw 2002-05-09
  • 打赏
  • 举报
回复
有呀,你可用javax.swing中的joptionpane类的showmessagedialog函数
ezyw 2002-05-09
  • 打赏
  • 举报
回复
有呀,你可用javax.swing中的joptionpane类的showmessagedialog函数

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧