Hi, im trying to open a new GUI window by clicking on a button. But for now what I manage to do is only get a black window. Here is my code.
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TesteWallet extends eWallet implements ActionListener{ eWallet SetAmt = new eWallet(); public String calculated = "Amount is $"; private JButton jbtSetMaxAmt = new JButton("Set"); private JButton jbtSetExpenditures = new JButton("Set"); private JButton jbtExpenditures = new JButton("Detail View"); public JButton jbtSetDetailExp = new JButton("Set"); private JLabel jlabelCurrentAmt = new JLabel("Current Available Amount"); private JLabel jlabelMaxAmt = new JLabel("Maximum Amount $"); private JLabel jlabelExpenditures = new JLabel("Expenditures $"); public JLabel jlabelFood = new JLabel("Food $"); public JLabel jlabelClothing = new JLabel("Clothing $"); public JLabel jlabelTransport = new JLabel("Transport $"); public JLabel jlabelSavings = new JLabel("Savings $"); private JTextField jtextCalculatedAmt = new JTextField(calculated); private JTextField jtextMaxAmt = new JTextField(""); private JTextField jtextExpenditures = new JTextField(""); public JTextField jtextFood = new JTextField(""); public JTextField jtextClothing = new JTextField(""); public JTextField jtextTransport = new JTextField(""); public JTextField jtextSavings = new JTextField(""); private JButton jbtCalculate = new JButton("Calculate"); static int jopIcon = JOptionPane.QUESTION_MESSAGE; boolean bFlag = true; //state, true means no exception public double cAmt; public TesteWallet(){ BorderLayout b = new BorderLayout(); setLayout(b); JPanel p = new JPanel(); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel(); //JPanel p4 = new JPanel(); p.setLayout(new GridLayout(3,1)); p1.setLayout(new GridLayout(3,1)); p2.setLayout(new GridLayout(4,1)); p3.setLayout(new GridLayout(3,1)); //p4.setLayout(new GridLayout(4,1)); jbtSetMaxAmt.setBackground(Color.yellow);//change background color jbtSetMaxAmt.setForeground(Color.black);//change font color jbtSetExpenditures.setBackground(Color.black);//change background color jbtSetExpenditures.setForeground(Color.red);//change font color jbtCalculate.setBackground(Color.green);//change background color jbtCalculate.setForeground(Color.yellow);//change font color p1.add(jlabelMaxAmt); p1.add(jtextMaxAmt); p1.add(jbtSetMaxAmt); p2.add(jlabelExpenditures); p2.add(jtextExpenditures); p2.add(jbtSetExpenditures); p2.add(jbtExpenditures); p3.add(jlabelCurrentAmt); p3.add(jtextCalculatedAmt); p3.add(jbtCalculate); //p4.add(jlabelFood); //p4.add(jtextFood); //p4.add(jlabelClothing); //p4.add(jtextClothing); //p4.add(jlabelTransport); //p4.add(jtextTransport); //p4.add(jtextSavings); //p4.add(jbtSetDetailExp); p.add(p1); p.add(p2); p.add(p3); add(p, BorderLayout.CENTER); jbtSetMaxAmt.addActionListener(this); jbtSetExpenditures.addActionListener(this); jbtExpenditures.addActionListener(this); jbtCalculate.addActionListener(this); } public void detailView(){ JFrame nFrame = new JFrame("Expenditures"); nFrame.setSize(500,300); nFrame.setLocationRelativeTo(null); nFrame.setVisible(true); BorderLayout c = new BorderLayout(); setLayout(c); JPanel pM = new JPanel(); JPanel p4 = new JPanel(); JPanel p5 = new JPanel(); JPanel p6 = new JPanel(); JPanel p7 = new JPanel(); JPanel p8 = new JPanel(); pM.setLayout(new GridLayout(4,1)); p4.setLayout(new GridLayout(2,1)); p5.setLayout(new GridLayout(2,1)); p6.setLayout(new GridLayout(2,1)); p7.setLayout(new GridLayout(2,1)); p8.setLayout(new GridLayout(1,1)); p4.add(jlabelFood); p4.add(jtextFood); p5.add(jlabelClothing); p5.add(jtextClothing); p6.add(jlabelTransport); p6.add(jtextTransport); p7.add(jlabelSavings); p7.add(jtextSavings); p8.add(jbtSetDetailExp); pM.add(p5); pM.add(p6); pM.add(p7); pM.add(p8); add(pM, BorderLayout.CENTER); } public static void main(String[] args){ TesteWallet frame = new TesteWallet(); //JFrame frame=new JFrame(); frame.setTitle("eWallet"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200,400); frame.setVisible( true ); //SetAmt.setCurrentAmt(jtextCurrentAmt); // System.out.println("diaply window, but set is invisible"); } /*public static void main(String[] args) { JFrame frame = new JFrame(); //sJFrame frame=new JFrame(); frame.setTitle("My Simple GUI - Drawing Shapes"); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); frame.setSize(400.0,250); JFrame.setVisible(true); }*/ @Override public void actionPerformed(ActionEvent e) { if (e.getSource()==jbtSetMaxAmt){ try { cAmt = Double.parseDouble(jtextMaxAmt.getText());//here, exception may come out if (cAmt < 0){ jtextMaxAmt.setText(""); JOptionPane.showMessageDialog(null, "Please Enter A Valid Amount.\n" + "Eg Any Number Larger Than '0'.\n"); } }catch(/*NumberFormat*/Exception nfe) { jtextMaxAmt.setText(""); JOptionPane.showMessageDialog(null, "Please Enter A Valid Amount.\n" + "Eg Any Number Larger Than '0'.\n"); } SetAmt.setMaxAmt(cAmt); } else if (e.getSource()==jbtSetExpenditures){ try { cAmt = Double.parseDouble(jtextExpenditures.getText());//here, exception may come out if (cAmt < 0){ jtextExpenditures.setText(""); JOptionPane.showMessageDialog(null, "Please Enter A Valid Amount.\n" + "Eg Any Number Larger Than '0'.\n"); } }catch(/*NumberFormat*/Exception nfe) { jtextExpenditures.setText(""); JOptionPane.showMessageDialog(null, "Please Enter A Valid Amount.\n" + "Eg Any Number Larger Than '0'.\n"); } SetAmt.setExpenditures(cAmt); } else if (e.getSource()==jbtExpenditures) { detailView(); } else if (e.getSource()==jbtCalculate) { if(SetAmt.getMaxAmt() > 0 ) { if(SetAmt.getExpenditures() > 0) { cAmt = SetAmt.getMaxAmt() - SetAmt.getExpenditures(); SetAmt.setCalculatedAmt(cAmt); jtextCalculatedAmt.setText("Amount is $" +cAmt); SetAmt.setMaxAmt(cAmt); if(cAmt>0) { JOptionPane.showMessageDialog(null, "It Is Safe To Spend Your Money\n"); } else { JOptionPane.showMessageDialog(null, "WARNING!\n You Have Exceeded Your Spending Limit.\n"); } } else { JOptionPane.showMessageDialog(null, "Please Enter Your Expenditures Amount."); } } else { JOptionPane.showMessageDialog(null, "Please Enter Your Maximum Amount."); } } } }