/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package windowtest; /** * * @author jcmt */ import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * * @author jcmt */ public class Window2Button extends JFrame implements ActionListener { private JButton bButton; private JButton cButton; private JButton adButton; private JButton muButton; private JFrame bwindow; private JPanel panel; private JTextField text; private static final String[] colorNames = {"Black", "Blue", "Green", "Yellow"}; private JList colorJList; private Integer n; private Integer n2; private int aP=0; private double ck=0; //private Purchase purchase; public Window2Button() { n = new Integer(0); bwindow = new JFrame("Sun"); //bwindow.setLocation(200, 200); bwindow.setSize(100, 100); bwindow.setBackground(Color.yellow); bwindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); bwindow.setVisible(true); } public void ListInAWindow(String[] args) { setLayout(new FlowLayout()); colorJList = new JList(args); colorJList.setVisibleRowCount(3); colorJList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); add ( new JScrollPane(colorJList)); setVisible(true); } public void AddBWindow( String[] args) { final int WINDOW_WIDTH = 200; final int WINDOW_HEIGHT = 200; //purchase = new Purchase(); //purchase.setTotalAmount(67.99); bwindow = new JFrame(); bwindow.setLocation(200, 200); bwindow.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); bwindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Value 1: "); //ck = purchase.getTotalAmount(); ck = 42; JLabel label2 = new JLabel(" " + ck+ " "); JLabel label3 = new JLabel("Value 2: "); JTextField num2 = new JTextField(10); String nu2 = num2.getText(); n2 = Integer.getInteger(nu2); adButton = new JButton("Add"); muButton = new JButton("Multiply"); bButton = new JButton("Back"); cButton = new JButton("Continue"); panel = new JPanel(); panel.add(label); panel.add(label2); panel.add(label3); panel.add(num2); panel.add(adButton); panel.add(muButton); panel.add(bButton); panel.add(cButton); adButton.setActionCommand("add"); muButton.setActionCommand("multiply"); bButton.setActionCommand("back"); cButton.setActionCommand("continue"); adButton.addActionListener(this); muButton.addActionListener(this); bButton.addActionListener(this); cButton.addActionListener(this); bwindow.add(panel); bwindow.setVisible(true); } /* private class Bbc extends ActionListener */ @Override public void actionPerformed(ActionEvent e) { if ("back".equals(e.getActionCommand())) { JOptionPane.showMessageDialog(Window2Button.this, String.format("Go Back")); } else if ("continue".equals(e.getActionCommand())) { JOptionPane.showMessageDialog(Window2Button.this, String.format("Continue")); } else if ("add".equals(e.getActionCommand())) { //String t = new String("Sum of 42 + "+ n2 + " = "+(n2+42)); JOptionPane.showMessageDialog(Window2Button.this, n2 ); } else if ("multiply".equals(e.getActionCommand())) { JOptionPane.showMessageDialog(Window2Button.this, String.format("Product of 42 + "+n2+ " = "+(n2*42))); } } }