import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
class Frame6 extends JFrame{
 private JPanel contentPane;
 private JButton button;
 Frame6(){
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setBounds(200,200,450,300);
  setTitle("Swing JFrame 視窗");
  
  contentPane = new JPanel();
  contentPane.setLayout(null);
  setContentPane(contentPane);
  
  button = new JButton("錯誤訊息");
  button.setBounds(100, 80, 100, 50);
  button.addActionListener(new ActionListener (){
   @Override
   public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    JOptionPane.showMessageDialog(null, "錯誤資訊","錯誤資訊視窗",JOptionPane.ERROR_MESSAGE);
   }
      
   });
  
  contentPane.add(button);
  
  setVisible(true);
 }
}
public class FrameOptionPane {
 public static void main(String[] args) {
  Frame6 frame = new Frame6();
 }
}
執行結果
點選按鈕
訊息種類
| Message Type常數 | 圖示 | 
|---|---|
| ERROR_MESSAGE | |
| INFORMATION_MESSAGE | |
| WARNING_MESSAGE | |
| QUESTION_MESSAGE | |
| PLAIN_MESSAGE | 沒有圖示 | 


沒有留言:
張貼留言