大哥你们来帮忙呀-------ping IP area ping t=new ping();//?????这是个什么类?ping类在哪有写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个程序错在什么地方呢。是不是没反应呢。 public static void main(String args[]){ JButton button=new JButton("the ping here");//你这个button又没有真正放上你的窗体上面,为什么要在这里建一个JButton呢。 ping t=new ping(); t.init(); xx bu=new xx(); button.addActionListener(bu);//这个是消息响应的吧。 你这个事件在哪里触发呢。 } 应该是在ping类的init()里面:xx bu = new xx();button.addActionListener(bu);而main里只要这样public static void main(String args[]){ ping t=new ping(); t.init(); } 试一试吧。 还有你的xx类里,为什么重新建这么多个Component呢,JTextField url1=new JTextField(10);JTextField url2=new JTextField(3);JTextField url3=new JTextField(3);String str1=url1.getText(); //这时str1为空的字符串String str2=url2.getText(); //str2同上String str3=url1.getText(); //str3同上在你下面的处理中没有什么意义的在你的这个类里的所有的Component都是重新申请的。你是要在窗体里获得你的输入然后输出吧。那么你的这两个类就要进行数据交流啦。 import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.io.*;public class ping extends JFrame { JFrame jframe=new JFrame("ping the area IP"); JPanel jp=new JPanel(); JLabel label1 = new JLabel("url1"); JLabel label2 = new JLabel("url2"); JLabel label3 = new JLabel("url3"); JTextField url1=new JTextField(10); JTextField url2=new JTextField(3); JTextField url3=new JTextField(3); JTextArea area=new JTextArea(10,25); JButton button=new JButton("the ping here"); String str1=url1.getText(); String str2=url2.getText(); String str3=url3.getText(); boolean shouldFill = true; public static void main(String args[]){ ping t=new ping(); t.init(); } void init(){ Container checkPanel = getContentPane(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); checkPanel.setLayout(gridbag); if (shouldFill) { c.fill = GridBagConstraints.HORIZONTAL; } c.gridx = 0; c.gridy = 0; gridbag.setConstraints(label1, c); checkPanel.add(label1); c.gridx = 1; c.gridy = 0; gridbag.setConstraints(url1, c); checkPanel.add(url1); c.gridx = 2; c.gridy = 0; gridbag.setConstraints(label2, c); checkPanel.add(label2); c.gridx = 3; c.gridy = 0; gridbag.setConstraints(url2, c); checkPanel.add(url2); c.gridx = 4; c.gridy = 0; gridbag.setConstraints(label3, c); checkPanel.add(label3); c.gridx = 5; c.gridy = 0; gridbag.setConstraints(url3, c); checkPanel.add(url3); c.gridx = 6; c.gridy = 0; gridbag.setConstraints(button, c); checkPanel.add(button); c.gridx = 0; c.gridy = 1; c.weightx=1; c.weighty=1; gridbag.setConstraints(area, c); checkPanel.add(area); button.addActionListener(this); jframe.getContentPane().add(checkPanel); jframe.pack(); jframe.setVisible(true); } // button.addActionListener(this); public void actionPerformed(ActionEvent ev) { /* JTextField url1=new JTextField(10); JTextField url2=new JTextField(3); JTextField url3=new JTextField(3); String str1=url1.getText(); String str2=url2.getText(); String str3=url1.getText(); JTextArea area=new JTextArea(10,25); */ try{ String s; InputStreamReader ir; BufferedReader in; for(int i=Integer.parseInt(str2);i<=Integer.parseInt(str3);i++) { // String s1= "218.191.84."; String cmd="ping "+str1+i+" -n 1"; // String cmd= "ping "+s1+i" -p; Process xx=Runtime.getRuntime().exec(cmd); InputStream ou=xx.getInputStream(); ir=new InputStreamReader(ou); in=new BufferedReader(ir); if((s=in.readLine())!=null) { area.append(str1+i+" OK!\n"); } else { area.append(str1+i+" ERROR!\n"); } } } catch(Exception e) { System.out.println(e); } }} 你的ping 类要实现ActionListener接口.即:public class ping extend JFrame implenments ActionListener这样应该就OK了吧! 还有InputStream、InputStreamReader 和 BufferedReader 用完时要关闭InputStream ou=xx.getInputStream();ir=new InputStreamReader(ou);in=new BufferedReader(ir);if((s=in.readLine())!=null){ area.append(str1+i+" OK!\n");}else{ area.append(str1+i+" ERROR!\n");}ou.close();ir.close();in.close(); import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.io.*;public class ping extends JFrame implements ActionListener { JFrame jframe =new JFrame("ping the area IP"); JPanel jp = new JPanel(); JLabel label1 = new JLabel("url1"); JLabel label2 = new JLabel("url2"); JLabel label3 = new JLabel("url3"); JTextField url1=new JTextField(10); JTextField url2=new JTextField(3); JTextField url3=new JTextField(3); JTextArea area=new JTextArea(10,25); JButton button=new JButton("the ping here"); boolean shouldFill = true; public static void main(String args[]){ ping t=new ping(); t.init(); } void init(){ Container checkPanel = getContentPane(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); checkPanel.setLayout(gridbag); if (shouldFill) { c.fill = GridBagConstraints.HORIZONTAL; } c.gridx = 0; c.gridy = 0; gridbag.setConstraints(label1, c); checkPanel.add(label1); c.gridx = 1; c.gridy = 0; gridbag.setConstraints(url1, c); checkPanel.add(url1); c.gridx = 2; c.gridy = 0; gridbag.setConstraints(label2, c); checkPanel.add(label2); c.gridx = 3; c.gridy = 0; gridbag.setConstraints(url2, c); checkPanel.add(url2); c.gridx = 4; c.gridy = 0; gridbag.setConstraints(label3, c); checkPanel.add(label3); c.gridx = 5; c.gridy = 0; gridbag.setConstraints(url3, c); checkPanel.add(url3); c.gridx = 6; c.gridy = 0; gridbag.setConstraints(button, c); checkPanel.add(button); c.gridx = 0; c.gridy = 1; c.weightx=1; c.weighty=1; gridbag.setConstraints(area, c); checkPanel.add(area); button.addActionListener(this); jframe.getContentPane().add(checkPanel); jframe.pack(); jframe.setVisible(true); } // button.addActionListener(this); public void actionPerformed(ActionEvent ev) { //注意 String str1=url1.getText(); //在这里获得JTextField里的文本才行的,否则str1、str2、str3都为空的。 String str2=url2.getText(); String str3=url3.getText(); try{ String s; InputStreamReader ir; BufferedReader in; for(int i=Integer.parseInt(str2);i<=Integer.parseInt(str3);i++) { // String s1= "218.191.84."; String cmd="ping "+str1+i+" -n 1"; // String cmd= "ping "+s1+i" -p; Process xx=Runtime.getRuntime().exec(cmd); InputStream ou=xx.getInputStream(); ir=new InputStreamReader(ou); in=new BufferedReader(ir); if((s=in.readLine())!=null) { area.append(str1+i+" OK!\n"); } else { area.append(str1+i+" ERROR!\n"); } ou.close(); ir.close(); in.close(); } } catch(Exception e) { System.out.println(e); } }} import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.InputStreamReader;import java.io.BufferedReader;import java.io.InputStream;import java.io.*;public class ping extends JFrame { JPanel contentPane; JScrollPane jScrollPane1 = new JScrollPane(); JTextArea jTextArea1 = new JTextArea(); JButton jButton1 = new JButton(); JLabel jLabel1 = new JLabel(); JTextField jTextField1 = new JTextField(10); JLabel jLabel2 = new JLabel(); JTextField jTextField2 = new JTextField(3); JLabel jLabel3 = new JLabel(); JTextField jTextField3 = new JTextField(3); //Construct the frame public ping() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { contentPane = (JPanel)this.getContentPane(); contentPane.setLayout(null); this.setLocale(java.util.Locale.getDefault()); this.setResizable(false); this.setSize(new Dimension(400, 300)); this.setTitle("Ping一个D段"); jScrollPane1.setBounds(new Rectangle(9, 66, 371, 195)); jTextArea1.setText(""); jButton1.setBounds(new Rectangle(239, 20, 87, 27)); jButton1.setText("开始Ping"); jButton1.addActionListener(new ping_jButton1_actionAdapter(this)); jLabel1.setText("A段"); jLabel1.setBounds(new Rectangle(13, 8, 38, 22)); jTextField1.setText(""); jTextField1.setBounds(new Rectangle(13, 34, 47, 22)); jLabel2.setText("B段"); jLabel2.setBounds(new Rectangle(80, 8, 38, 22)); jTextField2.setText(""); jTextField2.setColumns(3); jTextField2.setBounds(new Rectangle(80, 34, 47, 22)); jLabel3.setToolTipText(""); jLabel3.setText("C段"); jLabel3.setBounds(new Rectangle(147, 8, 38, 22)); jTextField3.setText(""); jTextField3.setBounds(new Rectangle(147, 34, 47, 22)); contentPane.add(jScrollPane1, null); jScrollPane1.getViewport().add(jTextArea1, null); contentPane.add(jTextField2, null); contentPane.add(jLabel2, null); contentPane.add(jLabel1, null); contentPane.add(jTextField1, null); contentPane.add(jLabel3, null); contentPane.add(jTextField3, null); contentPane.add(jButton1, null); } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void jButton1_actionPerformed(ActionEvent e) { //注意 String str1 = jTextField1.getText(); //在这里获得JTextField里的文本才行的,否则str1、str2、str3都为空的。 String str2 = jTextField2.getText(); String str3 = jTextField3.getText(); if (str1.equals("") || str2.equals("") || str3.equals("")) { JOptionPane.showMessageDialog(null, "请您输入您要查询的IP段", "出错", JOptionPane.ERROR_MESSAGE); return; } String s; InputStreamReader ir; BufferedReader in; for (int i = Integer.parseInt(str2); i <= Integer.parseInt(str3); i++) { // String s1= "218.191.84."; String cmd = "ping " + str1 + i + " -n 1"; // String cmd= "ping "+s1+i" -p; Process xx = null; try { xx = Runtime.getRuntime().exec(cmd); InputStream ou = xx.getInputStream(); ir = new InputStreamReader(ou); in = new BufferedReader(ir); if ( (s = in.readLine()) != null) { jTextArea1.append(str1 +"."+ i + " OK!\n"); } else { jTextArea1.append(str1 + "."+i + " ERROR!\n"); } ou.close(); ir.close(); in.close(); } catch (IOException ex1) { } } }}class ping_jButton1_actionAdapter implements java.awt.event.ActionListener { ping adaptee; ping_jButton1_actionAdapter(ping adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }} import javax.swing.UIManager;import java.awt.*;import javax.swing.*;import java.util.*;public class main { boolean packFrame = false; static Font f = new Font("Dialog", Font.PLAIN, 12); static Enumeration keys = UIManager.getLookAndFeelDefaults().keys(); //Construct the application public main() { ping frame = new ping(); //Validate frames that have preset sizes //Pack frames that have useful preferred size info, e.g. from their layout if (packFrame) { frame.pack(); } else { frame.validate(); } //Center the window Dimension screenSize = Toolkit.getDefaultToolkit(). getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); } //Main method public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager. getSystemLookAndFeelClassName()); while (keys.hasMoreElements()) { Object key = keys.nextElement(); if (UIManager.get(key)instanceof Font) { UIManager.put(key, f); } } } catch (Exception e) { e.printStackTrace(); } new main(); }} 请问这个正则表达式怎么写? 如何用for循环打出下面的图形 struts页面为何不编译 视频处理相关 串口发送短信的例子有源码 初学JAVA,遇到的一个问题。求助 easy thing!!!!!!!!! 下载jbuilder javaw.exe是干什么用的呀? 编译程序时出现[Message][ODBC 驱动程序 管理器]非法的描述器索引。是什么问题?? 请大家讨论,部署Java的方案有哪些? 分布式计算的课题_老老鸟请进!
public static void main(String args[]){
JButton button=new JButton("the ping here");//你这个button又没有真正放上你的窗体上面,为什么要在这里建一个JButton呢。
ping t=new ping();
t.init();
xx bu=new xx();
button.addActionListener(bu);//这个是消息响应的吧。
你这个事件在哪里触发呢。 }
应该是在ping类的init()里面:
xx bu = new xx();
button.addActionListener(bu);而main里只要这样
public static void main(String args[]){
ping t=new ping();
t.init();
} 试一试吧。
JTextField url1=new JTextField(10);
JTextField url2=new JTextField(3);
JTextField url3=new JTextField(3);
String str1=url1.getText(); //这时str1为空的字符串
String str2=url2.getText(); //str2同上
String str3=url1.getText(); //str3同上
在你下面的处理中没有什么意义的在你的这个类里的所有的Component都是重新申请的。
你是要在窗体里获得你的输入然后输出吧。
那么你的这两个类就要进行数据交流啦。
import javax.swing.*;
import java.awt.event.*;
import java.io.*;public class ping extends JFrame {
JFrame jframe=new JFrame("ping the area IP");
JPanel jp=new JPanel();
JLabel label1 = new JLabel("url1");
JLabel label2 = new JLabel("url2");
JLabel label3 = new JLabel("url3");
JTextField url1=new JTextField(10);
JTextField url2=new JTextField(3);
JTextField url3=new JTextField(3);
JTextArea area=new JTextArea(10,25);
JButton button=new JButton("the ping here");
String str1=url1.getText();
String str2=url2.getText();
String str3=url3.getText();
boolean shouldFill = true;
public static void main(String args[]){
ping t=new ping();
t.init();
}
void init(){
Container checkPanel = getContentPane();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
checkPanel.setLayout(gridbag);
if (shouldFill) {
c.fill = GridBagConstraints.HORIZONTAL;
}
c.gridx = 0;
c.gridy = 0;
gridbag.setConstraints(label1, c);
checkPanel.add(label1);
c.gridx = 1;
c.gridy = 0;
gridbag.setConstraints(url1, c);
checkPanel.add(url1); c.gridx = 2;
c.gridy = 0;
gridbag.setConstraints(label2, c);
checkPanel.add(label2); c.gridx = 3;
c.gridy = 0;
gridbag.setConstraints(url2, c);
checkPanel.add(url2); c.gridx = 4;
c.gridy = 0;
gridbag.setConstraints(label3, c);
checkPanel.add(label3); c.gridx = 5;
c.gridy = 0;
gridbag.setConstraints(url3, c);
checkPanel.add(url3); c.gridx = 6;
c.gridy = 0;
gridbag.setConstraints(button, c);
checkPanel.add(button); c.gridx = 0;
c.gridy = 1;
c.weightx=1;
c.weighty=1;
gridbag.setConstraints(area, c);
checkPanel.add(area);
button.addActionListener(this);
jframe.getContentPane().add(checkPanel);
jframe.pack();
jframe.setVisible(true);
} // button.addActionListener(this);
public void actionPerformed(ActionEvent ev)
{
/*
JTextField url1=new JTextField(10);
JTextField url2=new JTextField(3);
JTextField url3=new JTextField(3);
String str1=url1.getText();
String str2=url2.getText();
String str3=url1.getText();
JTextArea area=new JTextArea(10,25);
*/
try{
String s;
InputStreamReader ir;
BufferedReader in;
for(int i=Integer.parseInt(str2);i<=Integer.parseInt(str3);i++)
{
// String s1= "218.191.84.";
String cmd="ping "+str1+i+" -n 1";
// String cmd= "ping "+s1+i" -p;
Process xx=Runtime.getRuntime().exec(cmd);
InputStream ou=xx.getInputStream();
ir=new InputStreamReader(ou);
in=new BufferedReader(ir);
if((s=in.readLine())!=null)
{
area.append(str1+i+" OK!\n");
}
else
{
area.append(str1+i+" ERROR!\n");
}
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
即:public class ping extend JFrame implenments ActionListener
这样应该就OK了吧!
InputStream ou=xx.getInputStream();
ir=new InputStreamReader(ou);
in=new BufferedReader(ir);
if((s=in.readLine())!=null)
{
area.append(str1+i+" OK!\n");
}
else
{
area.append(str1+i+" ERROR!\n");
}
ou.close();
ir.close();
in.close();
import javax.swing.*;
import java.awt.event.*;
import java.io.*;public class ping extends JFrame implements ActionListener {
JFrame jframe =new JFrame("ping the area IP");
JPanel jp = new JPanel();
JLabel label1 = new JLabel("url1");
JLabel label2 = new JLabel("url2");
JLabel label3 = new JLabel("url3");
JTextField url1=new JTextField(10);
JTextField url2=new JTextField(3);
JTextField url3=new JTextField(3);
JTextArea area=new JTextArea(10,25);
JButton button=new JButton("the ping here"); boolean shouldFill = true;
public static void main(String args[]){
ping t=new ping();
t.init();
}
void init(){
Container checkPanel = getContentPane();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
checkPanel.setLayout(gridbag);
if (shouldFill) {
c.fill = GridBagConstraints.HORIZONTAL;
}
c.gridx = 0;
c.gridy = 0;
gridbag.setConstraints(label1, c);
checkPanel.add(label1);
c.gridx = 1;
c.gridy = 0;
gridbag.setConstraints(url1, c);
checkPanel.add(url1); c.gridx = 2;
c.gridy = 0;
gridbag.setConstraints(label2, c);
checkPanel.add(label2); c.gridx = 3;
c.gridy = 0;
gridbag.setConstraints(url2, c);
checkPanel.add(url2); c.gridx = 4;
c.gridy = 0;
gridbag.setConstraints(label3, c);
checkPanel.add(label3); c.gridx = 5;
c.gridy = 0;
gridbag.setConstraints(url3, c);
checkPanel.add(url3); c.gridx = 6;
c.gridy = 0;
gridbag.setConstraints(button, c);
checkPanel.add(button); c.gridx = 0;
c.gridy = 1;
c.weightx=1;
c.weighty=1;
gridbag.setConstraints(area, c);
checkPanel.add(area);
button.addActionListener(this);
jframe.getContentPane().add(checkPanel);
jframe.pack();
jframe.setVisible(true);
} // button.addActionListener(this);
public void actionPerformed(ActionEvent ev)
{
//注意
String str1=url1.getText(); //在这里获得JTextField里的文本才行的,否则str1、str2、str3都为空的。
String str2=url2.getText();
String str3=url3.getText();
try{
String s;
InputStreamReader ir;
BufferedReader in;
for(int i=Integer.parseInt(str2);i<=Integer.parseInt(str3);i++)
{
// String s1= "218.191.84.";
String cmd="ping "+str1+i+" -n 1";
// String cmd= "ping "+s1+i" -p;
Process xx=Runtime.getRuntime().exec(cmd);
InputStream ou=xx.getInputStream();
ir=new InputStreamReader(ou);
in=new BufferedReader(ir);
if((s=in.readLine())!=null)
{
area.append(str1+i+" OK!\n");
}
else
{
area.append(str1+i+" ERROR!\n");
}
ou.close();
ir.close();
in.close();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
import java.awt.event.*;
import javax.swing.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.*;public class ping
extends JFrame {
JPanel contentPane;
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
JButton jButton1 = new JButton();
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField(10);
JLabel jLabel2 = new JLabel();
JTextField jTextField2 = new JTextField(3);
JLabel jLabel3 = new JLabel();
JTextField jTextField3 = new JTextField(3); //Construct the frame
public ping() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
} //Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel)this.getContentPane();
contentPane.setLayout(null);
this.setLocale(java.util.Locale.getDefault());
this.setResizable(false);
this.setSize(new Dimension(400, 300));
this.setTitle("Ping一个D段");
jScrollPane1.setBounds(new Rectangle(9, 66, 371, 195));
jTextArea1.setText("");
jButton1.setBounds(new Rectangle(239, 20, 87, 27));
jButton1.setText("开始Ping");
jButton1.addActionListener(new ping_jButton1_actionAdapter(this));
jLabel1.setText("A段");
jLabel1.setBounds(new Rectangle(13, 8, 38, 22));
jTextField1.setText("");
jTextField1.setBounds(new Rectangle(13, 34, 47, 22));
jLabel2.setText("B段");
jLabel2.setBounds(new Rectangle(80, 8, 38, 22));
jTextField2.setText("");
jTextField2.setColumns(3);
jTextField2.setBounds(new Rectangle(80, 34, 47, 22));
jLabel3.setToolTipText("");
jLabel3.setText("C段");
jLabel3.setBounds(new Rectangle(147, 8, 38, 22));
jTextField3.setText("");
jTextField3.setBounds(new Rectangle(147, 34, 47, 22));
contentPane.add(jScrollPane1, null);
jScrollPane1.getViewport().add(jTextArea1, null);
contentPane.add(jTextField2, null);
contentPane.add(jLabel2, null);
contentPane.add(jLabel1, null);
contentPane.add(jTextField1, null);
contentPane.add(jLabel3, null);
contentPane.add(jTextField3, null);
contentPane.add(jButton1, null);
} //Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
} void jButton1_actionPerformed(ActionEvent e) {
//注意
String str1 = jTextField1.getText(); //在这里获得JTextField里的文本才行的,否则str1、str2、str3都为空的。
String str2 = jTextField2.getText();
String str3 = jTextField3.getText(); if (str1.equals("") || str2.equals("") || str3.equals("")) {
JOptionPane.showMessageDialog(null, "请您输入您要查询的IP段",
"出错",
JOptionPane.ERROR_MESSAGE);
return;
} String s;
InputStreamReader ir;
BufferedReader in;
for (int i = Integer.parseInt(str2); i <= Integer.parseInt(str3);
i++) {
// String s1= "218.191.84.";
String cmd = "ping " + str1 + i + " -n 1";
// String cmd= "ping "+s1+i" -p;
Process xx = null;
try {
xx = Runtime.getRuntime().exec(cmd);
InputStream ou = xx.getInputStream();
ir = new InputStreamReader(ou);
in = new BufferedReader(ir);
if ( (s = in.readLine()) != null) {
jTextArea1.append(str1 +"."+ i + " OK!\n");
}
else {
jTextArea1.append(str1 + "."+i +
" ERROR!\n");
}
ou.close();
ir.close();
in.close();
}
catch (IOException ex1) {
}
}
}
}class ping_jButton1_actionAdapter
implements java.awt.event.ActionListener {
ping adaptee; ping_jButton1_actionAdapter(ping adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
import java.awt.*;
import javax.swing.*;
import java.util.*;public class main {
boolean packFrame = false;
static Font f = new Font("Dialog", Font.PLAIN, 12);
static Enumeration keys = UIManager.getLookAndFeelDefaults().keys(); //Construct the application
public main() {
ping frame = new ping();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
} //Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.
getSystemLookAndFeelClassName());
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
if (UIManager.get(key)instanceof Font) {
UIManager.put(key, f);
}
} }
catch (Exception e) {
e.printStackTrace();
}
new main();
}
}