⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messagebox.java~15~

📁 java编的PL/0词法编译器
💻 JAVA~15~
字号:
package compiler;import java.awt.*;import java.awt.event.*;import javax.swing.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class MessageBox extends JDialog implements ActionListener{  public static final int ONLY_YES=0;//仅有"确定"按钮  public static final int ONLY_YES_NO=1;//仅有"是"和"否"按钮  public static final int YES_NO_CANCEL=2;//有"是","否"和"取消"三个按钮  public static final int YES=0;//用户回答"是"  public static final int NO=1;//用户回答"否"  public static final int CANCEL=3;//用户回答"取消"  private int type;//记录显示类型  private String message;//要显示的文字信息  private int answer;//记录用户的回答  JPanel contentPane= new JPanel();  JPanel messagePane=new JPanel();  JLabel messageLabel=new JLabel();//用于显示message  JPanel buttonPane=new JPanel();//用于存放各个按钮  JButton yesButton=new JButton();  JButton noButton=new JButton();  JButton cancelButton=new JButton();  public MessageBox(Frame frame, String title,int type,String message) {    super(frame, title,true);    this.type=type;    this.message=message;    enableEvents(AWTEvent.WINDOW_EVENT_MASK);    try {      jbInit();      pack();    }    catch(Exception ex) {      ex.printStackTrace();    }  }  private void jbInit() throws Exception {    contentPane=(JPanel)this.getContentPane();    contentPane.setLayout(new BorderLayout());    if(message.length()<25){      int i=25-message.length();      i/=2;      for(int j=0;j<i;j++)        message="  "+message;      for(int j=0;j<i;j++)        message=message+"  ";    }else{      message="     "+message+"     ";    }    messageLabel=new JLabel(message);    messagePane.setLayout(new BorderLayout());    messagePane.add(messageLabel,BorderLayout.CENTER);    contentPane.add(messagePane,BorderLayout.CENTER);    buttonPane.setLayout(new BorderLayout());    switch(type){      case ONLY_YES:        yesButton=new JButton("确定");        yesButton.addActionListener(this);        buttonPane.add(yesButton,BorderLayout.CENTER);        break;      case YES_NO_CANCEL:        cancelButton=new JButton("取消");        cancelButton.addActionListener(this);        buttonPane.add(cancelButton,BorderLayout.EAST);      case ONLY_YES_NO:        yesButton=new JButton("是 ");        yesButton.addActionListener(this);        buttonPane.add(yesButton,BorderLayout.WEST);        noButton=new JButton("否 ");        noButton.addActionListener(this);        buttonPane.add(noButton,BorderLayout.CENTER);        break;    }    contentPane.add(buttonPane,BorderLayout.SOUTH);    this.pack();    this.setResizable(false);  }  public void actionPerformed(ActionEvent e){  }  public int getAnswer(){    return answer;  }  //Overridden so we can exit when window is closed  protected void processWindowEvent(WindowEvent e) {    if (e.getID() == WindowEvent.WINDOW_CLOSING) {      answer=CANCEL;    }    super.processWindowEvent(e);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -