• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Continue button to go Next Frame?

 
Yatin Shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sir,

I am facing problem while cliking on button to continue next frame. One more thing I am aloso facing proble with ADD Button. I can not store given IP Address in List.txt file. Here, I am submititing my code below,

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.lang.*;
import java.io.*;
import java.lang.*;

/* <applet code=ServerInterface width=800 height=525 > </applet> */

public class ServerInterface extends JApplet
{

JPanel ButtonPanel, imageLabelPanel, LogoPanel, msuPanel, LabelPanel, welPanel, devPanel;
JLabel image,msu,msu2,wel,sms,dev,yat,blank,blank2;
JButton conti;
JFrame f;
String msg;

public void init()
{
Container contentPane = getContentPane();

/*
Create Panel for Name & Logo
*/

contentPane.add(imageLabelPanel = new JPanel(), BorderLayout.NORTH);
imageLabelPanel.setBackground(Color.white);

imageLabelPanel.add(LogoPanel = new JPanel(), BorderLayout.WEST);
//ImageIcon msuLogo = new ImageIcon("e:\\Logo.gif");
LogoPanel.setSize(10,25);
LogoPanel.setBackground(Color.white);
//LogoPanel.add(image = new JLabel(msuLogo));
//image.setIcon(new ImageIcon("Logo.gif"));

imageLabelPanel.add(msuPanel = new JPanel(), BorderLayout.EAST);
msuPanel.setLayout(new GridLayout(2,1));
msuPanel.setBackground(Color.white);
msuPanel.add(msu = new JLabel(" THE MAHARAJA SAYAJRAO "));
Font displayFont = new Font("Times New Roman", Font.BOLD, 29);
msu.setFont(displayFont);
msuPanel.add(msu2 = new JLabel(" UNIVERSITY OF BARODA"));
msu2.setFont(displayFont);

contentPane.add(LabelPanel = new JPanel());
LabelPanel.setLayout(new GridLayout(6,1));
LabelPanel.setBackground(Color.white);

LabelPanel.add(blank = new JLabel(" "));
LabelPanel.add(wel = new JLabel(" Welcome To..."));
wel.setFont(new Font("Monotype Corsiva",1,29));

LabelPanel.add(sms = new JLabel(" SERVER MONITORING SYSTEM"));
sms.setFont(new Font("Monotype Corsiva",1,39));

LabelPanel.add(blank2 = new JLabel(" "));

LabelPanel.add(dev = new JLabel(" Developed By :"));
dev.setFont(new Font("Monotype Corsiva",1,29));

LabelPanel.add(yat = new JLabel(" Yatin Shah"));
yat.setFont(new Font("Monotype Corsiva",1,33));

/*
Create Panel for Continue Button to go main Program
*/
contentPane.add(ButtonPanel = new JPanel(), BorderLayout.SOUTH);

conti = new JButton("CONTINUE");
ButtonPanel.add(conti);

WelcomePageEventHandler handler = new WelcomePageEventHandler(this);
conti.addActionListener(handler);
}

public void MainFrame()
{
if(msg.equals("CONTINUE"))
{
System.exit(0);
f=new NewMainFrame("Server Monitoring System",this);
}
}
}

class WelcomePageEventHandler implements ActionListener
{
ServerInterface si;

public WelcomePageEventHandler(ServerInterface ob)
{
si=ob;
}
public void actionPerformed(ActionEvent ae)
{
String msg=(String)ae.getActionCommand();
si.msg=msg;
si.MainFrame();
}
}

class NewMainFrame extends JFrame
{
JFrame f,ipList;
JLabel ln,le,lw,ls,lsn,lip,sil;
JLabel lsi[];
JPanel pc,pcs,si,ipPanel,lPanel,bPanel;
JButton sb[];
JButton badd,bedit,bdelete,bexit;
String msg;
JTextArea jta;

NewMainFrame(String title,ServerInterface ob)
{

Container contentpane=getContentPane();
contentpane.setLayout(new BorderLayout());

contentpane.add((ln=new JLabel(" SERVER MONITORING SYSTEM ")),BorderLayout.NORTH);
contentpane.add((le=new JLabel(" ")),BorderLayout.EAST);
contentpane.add((lw=new JLabel(" ")),BorderLayout.WEST);
contentpane.add((ls=new JLabel(" ")),BorderLayout.SOUTH);

Font titleFont = new Font("Monotype Corsiva", Font.BOLD, 36);
ln.setFont(titleFont);

contentpane.add(pc=new JPanel(),BorderLayout.CENTER);
pc.setLayout(new GridLayout(1,2));

jta=new JTextArea();
pc.add(jta);
jta.setEditable(false);
jta.setLayout(new FlowLayout(FlowLayout.CENTER));
jta.add(si = new JPanel(), BorderLayout.NORTH);

si.add(sil = new JLabel(" System Information"), BorderLayout.NORTH);
sil.setBackground(Color.white);
sil.setFont(new Font("Courier New",1,21));

pc.add(pcs=new JPanel());
pcs.setLayout(new FlowLayout(FlowLayout.CENTER));
pcs.add(ipPanel = new JPanel(), BorderLayout.NORTH);
pcs.add(lPanel = new JPanel());
pcs.add(bPanel = new JPanel(), BorderLayout.SOUTH);

ipPanel.add(lsn=new JLabel(" Server Name"));
lsn.setFont(new Font("Courier New",1,21));

ipPanel.add(lip=new JLabel(" IP Address"));
lip.setFont(new Font("Courier New",1,21));

String[] s = new String[100];
FileReader fr;
BufferedReader br;
int lineNo = 0,noLines;

try
{
fr = new FileReader("List.txt");
br = new BufferedReader(fr);

while((s[lineNo]=br.readLine()) != null)
lineNo++;

noLines = lineNo + 3;

lPanel.setLayout(new GridLayout(noLines,2));

for(int k = 0; k < 25; k++)
{
lPanel.add(sb[k]=new JButton("Telent"));

for(int i = 0; i < lineNo; i++)
{
if(i != -1)
{
lPanel.add(lsi[k]=new JLabel(s[i]));
}
}
}
br.close();
fr.close();

MyMainEventHandlerDesign handler = new MyMainEventHandlerDesign(this);

for(int j = 0; j < lineNo; j++)
{
sb[j].addActionListener(handler);
}

badd.addActionListener(handler);
bedit.addActionListener(handler);
bdelete.addActionListener(handler);
bexit.addActionListener(handler);
}


catch(NullPointerException npe)
{
System.out.println("Error : "+npe);
}

catch(FileNotFoundException fnfe)
{
System.out.println("File not found.... try another");
}

catch(IOException ioe)
{
System.out.println("I/0 Exception while reading file");
}

bPanel.add(badd=new JButton("ADD"));
bPanel.add(bedit=new JButton("EDIT"));
bPanel.add(bdelete=new JButton("DELETE"));
bPanel.add(bexit=new JButton("EXIT"));
}
public void doitnow()
{
if(msg.equals("ADD"))
{
f=new NewServerEntry("Add a Server",this);
}

if(msg.equals("EDIT"))
{
ipList=new EditServer("Edit a Server",this);
}

if(msg.equals("DELETE"))
{
ipList =new EditServer("Delete a Server",this);
}

if(msg.equals("EXIT"))
{
setVisible(false);
}
}
}


class MyMainEventHandlerDesign implements ActionListener
{
NewMainFrame nf;

public MyMainEventHandlerDesign(NewMainFrame ob)
{
nf=ob;
}
public void actionPerformed(ActionEvent ae)
{
String msg=(String)ae.getActionCommand();
nf.msg=msg;
nf.doitnow();
}
}


class NewServerEntry extends JFrame
{
NewMainFrame nf;
String arg;
JLabel lsn,lip;
JTextField tsn,tip;
JButton bok,bcancel;

NewServerEntry(String title,NewMainFrame ob)
{
super(title);
nf=ob;
Font addFont = new Font("Courier New", Font.BOLD, 18);

lsn=new JLabel("Enter Server Name :");
lsn.setFont(addFont);

lip=new JLabel("Enter IP Address :");
lip.setFont(addFont);

bok=new JButton("OK");
bcancel=new JButton("CANCEL");

tsn=new JTextField(20);
tip=new JTextField(20);

setSize(300,150);
setVisible(true);

goAhead();
}


public void goAhead()
{

Container contentpanense=getContentPane();

JPanel LabelPanel = new JPanel();
contentpanense.add(LabelPanel, BorderLayout.CENTER);
LabelPanel.setBackground(Color.white);
LabelPanel.setLayout(new GridLayout(2,2));
Border labelPanelBorder = BorderFactory.createTitledBorder("Add New Server");
LabelPanel.setBorder(labelPanelBorder);

LabelPanel.add(lsn);
LabelPanel.add(tsn);

LabelPanel.add(lip);
LabelPanel.add(tip);

JPanel ButtonPanel = new JPanel();
contentpanense.add(ButtonPanel, BorderLayout.SOUTH);

ButtonPanel.add(bok);
ButtonPanel.add(bcancel);

MyEventHandlerNse handler=new MyEventHandlerNse(this);
bok.addActionListener(handler);
bcancel.addActionListener(handler);
}


public void doitnowNse()
{
if(arg.equals("OK"))
{

}

if(arg.equals("CANCEL"))
{
setVisible(false);
}
}
}

class EditServer extends JFrame
{
NewMainFrame nf;
String arg;
JList IPlist;
JTextField valueField;
JButton bok,bcancel;

public EditServer(String title,NewMainFrame ob)
{
super(title);
nf=ob;

Container content = getContentPane();

/*
Create the JList, set the numer of visible rows, add a listener,
and put it in a JScrollPane.
*/

String[] s = new String[100];
FileReader fr;
BufferedReader br;
int lineNo = 0,noLines;

try
{
fr = new FileReader("List.txt");
br = new BufferedReader(fr);

while((s[lineNo]=br.readLine()) != null)
lineNo++;

IPlist = new JList(s);

br.close();
fr.close();

Font displayFont = new Font("Courier New", Font.BOLD, 18);
IPlist.setVisibleRowCount(3);
IPlist.setFont(displayFont);
IPlist.addListSelectionListener(new ValueReporter());

JScrollPane listPane = new JScrollPane(IPlist);
JPanel listPanel = new JPanel();
listPanel.setBackground(Color.white);

JLabel valueLabel = new JLabel("Selected IP Address :");
valueLabel.setFont(displayFont);
valueField = new JTextField("None", 15);
valueField.setFont(displayFont);
JPanel valuePanel = new JPanel();
valuePanel.setBackground(Color.white);
Border valuePanelBorder = BorderFactory.createTitledBorder("Selection Of IP Address");
valuePanel.setBorder(valuePanelBorder);
valuePanel.add(valueLabel);
valuePanel.add(valueField);
content.add(valuePanel, BorderLayout.CENTER);

Border listPanelBorder = BorderFactory.createTitledBorder("List Of IP Addresses");
listPanel.setBorder(listPanelBorder);
JLabel label = new JLabel("Select IP Address :");
label.setFont(displayFont);
listPanel.add(label);

listPanel.add(listPane);
content.add(listPanel, BorderLayout.SOUTH);

bok=new JButton("OK");
bcancel=new JButton("CANCEL");

listPanel.add(bok);
listPanel.add(bcancel);

MyEventHandlerEdit handler=new MyEventHandlerEdit(this);
bok.addActionListener(handler);
bcancel.addActionListener(handler);

pack();
setVisible(true);

}

catch(FileNotFoundException fnfe)
{
System.out.println("File not found.... try another");
}

catch(IOException ioe)
{
System.out.println("I/0 Exception while reading file");
}

}

public void doitnowEdit()
{
if(arg.equals("OK"))
{

}
if(arg.equals("CANCEL"))
{
setVisible(false);
}
}

private class ValueReporter implements ListSelectionListener
{
public void valueChanged(ListSelectionEvent lse)
{
if(!lse.getValueIsAdjusting())
valueField.setText(IPlist.getSelectedValue().toString());
}
}
}

class MyEventHandlerNse implements ActionListener
{

NewServerEntry nse;

public MyEventHandlerNse(NewServerEntry ob)
{
nse=ob;
}
public void actionPerformed(ActionEvent ae)
{
String arg = (String)ae.getActionCommand();
nse.arg=arg;
nse.doitnowNse();
}
}

class MyEventHandlerEdit implements ActionListener
{

EditServer es;

public MyEventHandlerEdit(EditServer ob)
{
es=ob;
}
public void actionPerformed(ActionEvent ae)
{
String arg = (String)ae.getActionCommand();
es.arg=arg;
es.doitnowEdit();
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!