I am new to this forum,please pardon my mistakes.I want to link these two java classes together.here are my codes.
AustasMain.java(A)
import java.awt.event.ActionListener.*; import java.awt.event.ActionEvent; import java.awt.*; import java.awt.event.*; import java.awt.Label.*; import javax.swing.*; import java.awt.Graphics; import java.awt.Graphics2D; import java.sql.*; public class AustasMain extends JPanel { String user; double pass; double pass1=1234; String userr="user"; Label username,password; TextField username1,password1; private JButton ok; private JTextArea textarea; private SecMain sec; public AustasMain () { setLayout(new FlowLayout()); username=new Label("USERNAME");add(username); username1= new TextField(10);add(username1); password=new Label("PASSWORD");add(password); password1=new TextField(10);add(password1); ok=new JButton("OK");add(ok); TextHandler handler=new TextHandler(); username1.addActionListener(handler); password1.addActionListener(handler); ok.addActionListener(handler); } class TextHandler implements ActionListener { public void actionPerformed(ActionEvent event) { if(event.getSource()==username1){ String user=(username1.getText()); } if(event.getSource()==password1){ double pass=Double.parseDouble(password1.getText()); } if(event.getSource()==ok) { String user=(username1.getText()); int pars=Integer.parseInt(password1.getText()); String pass=(password1.getText()); double pass1=1234; String userr="user"; try{ if(user.equals("") && pass.equals("")) { JOptionPane.showMessageDialog(null,"Enter login name or password","Error",JOptionPane.ERROR_MESSAGE); } else if (user.equals("user") && pass.equals("400")) { // this calls the class below.here A passes to B. SecsMain sec=new SecsMain(); sec.pas=pars; sec.setVisible(true); } else { JOptionPane.showMessageDialog(null,"Invalid login name or password","Error",JOptionPane.ERROR_MESSAGE); username1.setText(""); password1.setText(""); } } catch(Exception e){} } } } public static void main(String [] args) { AustasMain panel=new AustasMain(); JFrame frame=new JFrame("LOGIN FORM"); frame.setSize(250,200); frame.add(panel); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
the second class is :
Secs.java(B)
//The program compiles but does not call the second program when the username and password is correctly entered.Please help me.import java.awt.*; // import java.awt.event.*; // PACKAGES import javax.swing.*; // import java.sql.*; // import java.awt.event.ActionListener.*; import java.awt.event.ActionEvent; public class SecsMain extends JFrame implements ActionListener { private JButton mkt,acct,store;int pas; //-----Constructor------ public SecsMain() { super("DEPARTMENTS"); setLayout(new GridLayout(1,4)); mkt = new JButton("MARKET"); mkt.setPreferredSize(new Dimension(150,300)); mkt.setSize(mkt.getPreferredSize()); mkt.addActionListener(this); add(mkt); acct = new JButton("ACCOUNT"); acct.setPreferredSize(new Dimension(150,300)); acct.setSize(acct.getPreferredSize()); acct.addActionListener(this); add(acct); JButton store= new JButton ("STORE"); store.setPreferredSize(new Dimension(150,300)); store.setSize(store.getPreferredSize()); add(store); JButton md= new JButton ("MD"); md.setPreferredSize(new Dimension(150,300)); md.setSize(md.getPreferredSize()); add(md); setSize(pas,300); } public void actionPerformed(ActionEvent event) { } }