Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private JFrame container;
- private JButton buttonYes;
- private JButton buttonNo;
- private JButton buttonCancel;
- public enum buttonState {BUTTON_YES, BUTTON_NO, BUTTON_CANCEL};
- public static buttonState actualState = null;
- public BOptionPane1(){
- }
- public buttonState ShowBOptionPane1(){
- this.container = new JFrame("Dialogo");
- this.container.setSize(300, 100);
- this.container.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.container.setVisible(true);
- FlowLayout flowLayout = new FlowLayout();
- this.container.setLayout(flowLayout);
- this.buttonYes = new JButton("Yes");
- this.buttonNo = new JButton("No");
- this.buttonCancel = new JButton("Cancel");
- container.add(buttonYes);
- container.add(buttonNo);
- container.add(buttonCancel);
- buttonYes.addActionListener(this);
- buttonNo.addActionListener(this);
- buttonCancel.addActionListener(this);
- //Here, my strange custom component will have been created by ShowBOptionPane1
- //Now I need wait until user click a button, after that, test() will be called.
- return test();
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- switch (e.getActionCommand()){
- case "Yes":
- this.actualState = buttonState.BUTTON_YES;
- break;
- case "No":
- this.actualState = buttonState.BUTTON_NO;
- break;
- default:
- this.actualState = buttonState.BUTTON_CANCEL;
- break;
- }
- this.container.setVisible(false);
- }
- public buttonState test(){
- return this.actualState;
- }
- public ViewExample(){
- JFrame backContainer = new JFrame("Titulo ViewExample");
- backContainer.setSize(500, 300);
- backContainer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- backContainer.setVisible(true);
- FlowLayout flowLayout = new FlowLayout();
- backContainer.setLayout(flowLayout);
- JButton buttonPlay = new JButton("Play");
- JButton buttonStop = new JButton("Stop");
- JButton buttonPause = new JButton("Pause");
- backContainer.add(buttonPlay);
- backContainer.add(buttonStop);
- backContainer.add(buttonPause);
- buttonStop.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- BOptionPane1 bOptionPane1 = new BOptionPane1();
- BOptionPane1.buttonState result = bOptionPane1.ShowBOptionPane1();
- System.out.println("Este es el resultado: " + result);
- }
- });
- }
- public static void main(String[] args) {
- ViewExample cursoVideotutoriales = new ViewExample();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement