• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with EDIT button.  RSS feed

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

My project is Server Monitoring System. I am facing probelm with edit button. My problem is while I am going to edit IP address if IP is already exist then it should display message "IP Address alrady exist!". Its showing the message. But the problem is that sometimes my code not replacing that IP address which are already exist and sometimes doing. I am attaching my code here with this code perform while user click on OK button:

One more thing I want to do is that if editing has been done then my JList should be refresh if user want to edit more. Please, help me.

public void doitnowEdit()
{
int IPline = 0,Nline = 0;

if (arg.equals("OK"))
{
try
{
fr1 = new FileReader("IPList.txt");
br1 = new BufferedReader(fr1);

while((sIP[IPline]=br1.readLine()) != null)
IPline++;

fr1.close();
br1.close();

fr2 = new FileReader("NameList.txt");
br2 = new BufferedReader(fr2);

while((sName[Nline]=br2.readLine()) != null)
Nline++;

fr2.close();
br2.close();

fw1 = new FileWriter("IPList.txt");
pw1 = new PrintWriter(fw1);

fw2 = new FileWriter("NameList.txt");
pw2 = new PrintWriter(fw2);

String name = SnField.getText();
String IP = IPField.getText();

boolean isPrint = true;
int c = IP.length();
int count = 0,dot = 0;

if( (name.equals("")) || (IP.equals("")) )
{
JOptionPane.showMessageDialog(null,"Please, Enter value in both field.","Alert!", JOptionPane.INFORMATION_MESSAGE);
isPrint = false;
}

while( count < c)
{
char ch = IP.charAt(count);
if( ch == '.')
dot++;

count++;
}

if(dot < 3 || dot > 3)
{
JOptionPane.showMessageDialog(null,"Invalid IP Address!","Warning!", JOptionPane.WARNING_MESSAGE);
isPrint = false;
IPField.setText("");
}
for(int i = 0; i < IPline; i++)
{
if(IP.equals(sIP[i]))
{
isPrint = false;
JOptionPane.showMessageDialog(null,"IP Address already exist!","Warning!", JOptionPane.WARNING_MESSAGE);
pw1.println(sIP[i]);
pw2.println(sName[i]);
}

else if( (isPrint) && ( (temp.equals(sIP[i])) && (tName.equals(sName[i])) ) )
{
pw1.println(IP);
pw2.println(name.toUpperCase());
}

else
{
pw1.println(sIP[i]);
pw2.println(sName[i]);
}
}

fw1.close();
pw1.close();

fw2.close();
pw2.close();
}

catch(FileNotFoundException fnfe)
{
JOptionPane.showMessageDialog(null, "File not found !", "Error !",JOptionPane.ERROR_MESSAGE);
}

catch(IOException ioe)
{
JOptionPane.showMessageDialog(null, "I/O Exception while reading file !", "Error !",JOptionPane.ERROR_MESSAGE);
}

int returnValue = JOptionPane.showConfirmDialog(null,"Do you want to Edit another?","Question",JOptionPane.YES_NO_OPTION);

if(returnValue == JOptionPane.NO_OPTION)
{
setVisible(false);
si.badd.setEnabled(true);
si.bedit.setEnabled(true);
si.bdelete.setEnabled(true);
si.bexit.setEnabled(true);
}

if(returnValue == JOptionPane.YES_OPTION)
{
SnField.setText("");
IPField.setText("");
IPlist.requestFocus();
}
si.refreshFrame();

}



Thanking You
Yatin
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!