Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. private JFrame container;
  2. private JButton buttonYes;
  3. private JButton buttonNo;
  4. private JButton buttonCancel;
  5.  
  6. public enum buttonState {BUTTON_YES, BUTTON_NO, BUTTON_CANCEL};
  7. public static buttonState actualState = null;
  8.  
  9. public BOptionPane1(){
  10.  
  11. }
  12.  
  13. public buttonState ShowBOptionPane1(){
  14.  
  15. this.container = new JFrame("Dialogo");
  16. this.container.setSize(300, 100);
  17. this.container.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  18. this.container.setVisible(true);
  19.  
  20. FlowLayout flowLayout = new FlowLayout();
  21. this.container.setLayout(flowLayout);
  22.  
  23. this.buttonYes = new JButton("Yes");
  24. this.buttonNo = new JButton("No");
  25. this.buttonCancel = new JButton("Cancel");
  26.  
  27. container.add(buttonYes);
  28. container.add(buttonNo);
  29. container.add(buttonCancel);
  30.  
  31. buttonYes.addActionListener(this);
  32. buttonNo.addActionListener(this);
  33. buttonCancel.addActionListener(this);
  34.  
  35. //Here, my strange custom component will have been created by ShowBOptionPane1
  36. //Now I need wait until user click a button, after that, test() will be called.
  37.  
  38. return test();
  39. }
  40.  
  41. @Override
  42. public void actionPerformed(ActionEvent e) {
  43.  
  44. switch (e.getActionCommand()){
  45. case "Yes":
  46. this.actualState = buttonState.BUTTON_YES;
  47. break;
  48. case "No":
  49. this.actualState = buttonState.BUTTON_NO;
  50. break;
  51. default:
  52. this.actualState = buttonState.BUTTON_CANCEL;
  53. break;
  54. }
  55. this.container.setVisible(false);
  56. }
  57.  
  58. public buttonState test(){
  59. return this.actualState;
  60. }
  61.  
  62. public ViewExample(){
  63.  
  64. JFrame backContainer = new JFrame("Titulo ViewExample");
  65. backContainer.setSize(500, 300);
  66. backContainer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  67. backContainer.setVisible(true);
  68.  
  69. FlowLayout flowLayout = new FlowLayout();
  70. backContainer.setLayout(flowLayout);
  71.  
  72. JButton buttonPlay = new JButton("Play");
  73. JButton buttonStop = new JButton("Stop");
  74. JButton buttonPause = new JButton("Pause");
  75.  
  76. backContainer.add(buttonPlay);
  77. backContainer.add(buttonStop);
  78. backContainer.add(buttonPause);
  79.  
  80. buttonStop.addActionListener(new ActionListener() {
  81. @Override
  82. public void actionPerformed(ActionEvent e) {
  83. BOptionPane1 bOptionPane1 = new BOptionPane1();
  84. BOptionPane1.buttonState result = bOptionPane1.ShowBOptionPane1();
  85. System.out.println("Este es el resultado: " + result);
  86. }
  87. });
  88. }
  89.  
  90. public static void main(String[] args) {
  91. ViewExample cursoVideotutoriales = new ViewExample();
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement