import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;class Y2 extends JFrame {
public Y2() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
} public static void main(String args[]) {
System.out.println("Starting Y2...");
Y2 mainFrame = new Y2();
mainFrame.setSize(400, 400);
mainFrame.setTitle("撒旦");
JTextField t = new JTextField("请输入您的主机名");
JButton b = new JButton("确定");
String tx = t.getText();
ipa a = new ipa(tx); //为什么这个传不下去!!!!!
mainFrame.getContentPane().setLayout(new FlowLayout());
mainFrame.getContentPane().add(t);
mainFrame.getContentPane().add(b);
b.addActionListener(a);
mainFrame.setVisible(true);
}
}
class ipa implements ActionListener{
private String text;
public void ipa(String w)
{
text=w;
}
public void actionPerformed(ActionEvent e)
{
try{
InetAddress a = InetAddress.getByName(text);
结果怎么在能传个上面的文本框!!!!!
}
catch (UnknownHostException f){
System.err.println("您输入的主机名正确吗");
}
}
}
import java.awt.event.*;
import javax.swing.*;
import java.net.*;class Y2 extends JFrame {
public Y2() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
} public static void main(String args[]) {
System.out.println("Starting Y2...");
Y2 mainFrame = new Y2();
mainFrame.setSize(400, 400);
mainFrame.setTitle("撒旦");
JTextField t = new JTextField("请输入您的主机名");
JButton b = new JButton("确定");
String tx = t.getText();
ipa a = new ipa(tx); //为什么这个传不下去!!!!!
mainFrame.getContentPane().setLayout(new FlowLayout());
mainFrame.getContentPane().add(t);
mainFrame.getContentPane().add(b);
b.addActionListener(a);
mainFrame.setVisible(true);
}
}
class ipa implements ActionListener{
private String text;
public void ipa(String w)
{
text=w;
}
public void actionPerformed(ActionEvent e)
{
try{
InetAddress a = InetAddress.getByName(text);
结果怎么在能传个上面的文本框!!!!!
}
catch (UnknownHostException f){
System.err.println("您输入的主机名正确吗");
}
}
}
解决方案 »
- RandomAccessFile中seek方法是什么意思
- 关于多个Jpanel在Jframe里布局换行的问题,我贴出一段代码大家帮我看下,还有为什么Jtable的标题只显示一个,有图。
- 请教:定义一个Student类,要求在程序中生成若干个Student对象,并将这些对象分别保存到ArrayList和HashSet中,然后遍历的输出出来。我这样
- 求教一JAVA面试题
- 我是一个初学者,为什么用SYSTEM.IN.READ()不能从键盘那读字符?如何从键盘读一个字符
- 聊天程序小问题?
- 调试程序输出出错.求助
- 请问用java编好的软件,如何打包发布呀?急~~~
- 画图时的java.lang.NullPointerException错误
- java自动类型转换的问题
- 急!数据库问题,在线求答!
- 关于英文XP上jdk1.5的中文问题
InetAddress a = InetAddress.getByName(t.getText());
{
text=w;
}
to:
public ipa(String w)
{
text=w;
}
try{
InetAddress a = InetAddress.getByName(text);
//结果怎么在能传个上面的文本框!!!!!
}catch (UnknownHostException f){
System.err.println("您输入的主机名正确吗");
}
}
只能接收第一次传过来的,第二次的根本没执行,你试试这个,我测过了:
/*
* Created on 2005-4-28
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package awtPackage;/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;public class Y2 extends JFrame { public static JTextField t = new JTextField("请输入您的主机名");
public Y2() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
} public static void main(String args[]) {
System.out.println("Starting Y2...");
Y2 mainFrame = new Y2();
mainFrame.setSize(400, 400);
mainFrame.setTitle("撒旦");
JButton b = new JButton("确定");
String tx = t.getText();
ipa a = new ipa(tx); //为什么这个传不下去!!!!!
mainFrame.getContentPane().setLayout(new FlowLayout());
mainFrame.getContentPane().add(t);
mainFrame.getContentPane().add(b);
b.addActionListener(a);
mainFrame.setVisible(true);
}
}
class ipa implements ActionListener{
private String text;
public ipa(String w){
System.out.println(1);
text=w;
}
public void actionPerformed(ActionEvent e){
text = Y2.t.getText();
System.out.println(text);
try{
InetAddress a = InetAddress.getByName(text);
//结果怎么在能传个上面的文本框!!!!!
}catch (UnknownHostException f){
System.err.println("您输入的主机名正确吗");
}
}
}