Home Tutorialhelp Comment how to insert and remove in/from string array?

 
 

Comment

Mehmet
how to insert and remove in/from string array?,
July 10, 2008 at 7:52 PM

how can ý add and remove an item into/from a string array? ý couldnt find this. the program is here. please help me. thanks by

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class Pnng extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
String ips[]={"192.168.1.1","192.168.1.3","10.1.1.99","10.1.1.101","10.1.1.110",
"10.1.1.1","10.1.1.2","10.1.1.25","10.1.1.30","10.1.1.28","10.1.1.43",
"10.1.1.49","10.1.1.27","10.1.1.29","10.1.1.40","10.1.1.45","10.1.1.47",
"10.1.1.90","10.1.1.50"};
boolean reachable = false;
JTextArea ta = new JTextArea(20,20);
JTextField tf = new JTextField(9);
public static void main(String []args){
Pnng win = new Pnng();
win.setTitle("Pinger");
}
Pnng(){
JPanel content = new JPanel();
content.setLayout(new FlowLayout());
//JComboBox cb = new JComboBox(ips);
JScrollPane sp = new JScrollPane(ta);
JButton pingbtn = new JButton("Ping");
pingbtn.addActionListener(new pingbtnBtnListener());
JButton clrbtn = new JButton("Clear");
clrbtn.addActionListener(new clrbtnBtnListener());
JButton addbtn = new JButton("Add Ip");
addbtn.addActionListener(new addbtnBtnListener());
JButton removebtn = new JButton("Remove");

removebtn.addActionListener(new removebtnBtnListener());
//content.add(cb);
content.add(sp);
content.add(pingbtn);
content.add(clrbtn);
content.add(addbtn);
content.add(removebtn);
content.add(tf);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(1,2));
mainPanel.add(content);
setContentPane(mainPanel);
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class addbtnBtnListener implements ActionListener{
public void actionPerformed(ActionEvent arg0){
for(int j=0;j<ips.length;j++)
ips.(tf.getText());
}
}
class removebtnBtnListener implements ActionListener{
public void actionPerformed(ActionEvent arg0){
String sonuncu =ips.pop();
}
}
class clrbtnBtnListener implements ActionListener{
public void actionPerformed(ActionEvent arg0){
ta.setText("");
}
}
class pingbtnBtnListener implements ActionListener{
public void actionPerformed(ActionEvent arg0){
for(int i=0;i<ips.length;i++)
{
ta.append("IP Adress: "+ips[i]+" "+"\n");
try
{
reachable = windows_ping(ips[i]);
}
catch(Exception e)
{
e.printStackTrace();

}
if(reachable)
ta.append("reachable...!!!"+"\n\n");
else
ta.append("unreachable...!!!"+"\n\n");

}
}
public boolean windows_ping(String ip) throws Exception {
Process p = Runtime.getRuntime().exec("ping -n 1 -w 100 -l 8 " + ip);
int status = p.waitFor();
return status==0?true:false;
}
}
}
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Java Beginners

String Array - Java Beginners
 

Java Beginners

How to Remove Repeated Characters from the String?
 

Java Code Examples

Java Remove a character from string
 

Java Interview Questions

remove a substring from a string
 

Java Code Examples

Remove duplicate characters from the string
 

Java Beginners

String Array - Java Beginners
 

PHP Questions

remove comma from string php
 

PHP Questions

remove comma from string php
 

Java Beginners

sorting an array of string with duplicate values - Java Beginners
 

Java Beginners

string
 

Java Beginners

string
 

Java Beginners

java String array - Java Beginners
 

Mobile Applications Questions

array to string
 

Java-Tutorials

How To Remove Array Element In Java
 

JSP Servlet Questions

String array sort
 

JSP Servlet Questions

String array sort
 

Java Beginners

How to convert Arraylist into String Array Java
 

Java Beginners

String Array - Java Beginners
 

General

Remove Repeated Characters from the String
 

C Tutorials

C String Remove Spaces
 

Java Tips and Examples

String Array In Java
 

Java Beginners

sorting an array of string with duplicate values - Java Beginners
 

Java Beginners

String
 

General

Insert and Delete an element in between an array
 

Java Beginners

string
 

Java Beginners

String
 

Java Beginners

string - Java Beginners
 

Java Beginners

string
 

Java Beginners

String
 

Java Beginners

string - Java Beginners
 

Java Beginners

string
 

Java Beginners

string
 

Java Beginners

string - Java Beginners
 

General

String Array
 

JavaScript Questions

array string
 

JavaScript Questions

create a string from an array using JavaScript
 

Java Beginners

sorting an array of string with duplicate values - Java Beginners
 

Java Beginners

String in Java - Java Beginners
 

Java Beginners

sorting an array of string with duplicate values - Java Beginners
 

Java Beginners

how to insert and retrieve an image from mysql using java - Java Beginners
 

Java Beginners

Merge Sort String Array in Java
 

Java Beginners

Java dom from string
 

Java Beginners

string - Java Beginners
 

Java Interview Questions

string manipulation
 

Java Interview Questions

string manipulation
 

Java Beginners

ROTATE THE VOWELS IN A STRING!!! - Java Beginners
 

Java Tips and Examples

Summary - String
 

General

Javascript array for string
 

Java Tips and Examples

Convert Array to String
 

Java Beginners

Java String - Java Beginners
 

Java Interview Questions

Java String operations
 

Java Beginners

How to return a string from a JTextField
 

SQL Question

Removing character from a string in sql.
 

Java-Tutorials

Java String To Date
 

JSP Servlet Questions

string array sort
 

JSP Servlet Questions

string array sort
 

JSP Servlet Questions

string array sort
 

JSP Servlet Questions

string array sort
 

JSP Servlet Questions

string array sort
 

General

Java arraylist to string array
 

Struts Questions

how to pass string array from action class to jsp page? pls reply me.
 

Java Interview Questions

remove element from stack
 

PHP Questions

php parse string into array
 

Core Java Tutorials

Write a method which will remove any given character from a string?
 

Java Beginners

query String - Java Beginners
 

Java Beginners

how to write to file from string in Java
 

JSP Servlet Questions

JSP to output Java String Array - JSP-Servlet
 

Java-Tutorials

String Reverse In Java Example
 

JSP Servlet Questions

how to Insert Array Values Into Separate Rows using java?
 

Java Beginners

java class string - Java Beginners
 

Java Beginners

Array
 

Java Beginners

Sorting String arrays in java - Java Beginners
 

Java Tips and Examples

Java String Occurrence in a String
 

Struts Questions

How to pass Array of string from action class to jsp page
 

General

Get Character from String
 

Java Code Examples

Java insertion sort with string array
 

Java Beginners

How to convert a String to an int?
 

Java Beginners

initialise array by reading from file - Java Beginners
 

General

How to declare String array in Java?
 

Java Beginners

how to convert string to image in java
 

Java Interview Questions

array, index, string
 

JavaScript Questions

JavaScript split string into array
 

Design concepts & design patterns Questions

string
 

Java Beginners

array in javascript - Java Beginners
 

Struts Questions

to retrieve from radiobox and comparing with a string - Struts
 

Java Beginners

How to evaluate the mathematical expression from the string in J2ME.
 

Mobile Applications Questions

How to evaluate the mathematical expression from the string in J2ME.
 

Java Beginners

What is the first argument of the String array in main() method?
 

Java Interview Questions

Array List and string operation
 

Java Beginners

array split string
 

Programming Tutorials

JavaScript Remove Spaces
 

Core Java

How to remove specific element from Hashset.
 

Java Beginners

string
 

Java Beginners

String
 

Java Beginners

string
 

Java Beginners

string
 

Java Beginners

String
 

Java Beginners

string
 

Java Beginners

i need a quick response about array and string...
 

Java Beginners

string
 

Advertisements Advertisements
 

 

 

DMCA.com