1个回答
2016-05-05 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
很简单的,就是通过参数传递的方法!
:
//这是b.java文件
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class b extends JFrame implements ActionListener{
JButton button1=new JButton("显示窗体a");
public b()
{
super("我是窗体b");
this.setBounds(250,80,350,400);
this.setVisible(true);
this.setResizable(false);
button1.setBounds(35,140,70,20);
button1.addActionListener(this);
this.add(button1);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button1)
{
String title ="我是窗体b传过来的值";
new a(title);
}
}
public static void main(String argv[])
{
new b();
}
}
//这是a.java文件
/**
* Created with IntelliJ IDEA.
* User: Administrator
* Date: 12-6-19
* Time: 上午7:31
* To change this template use File | Settings | File Templates.
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class a extends JFrame{
JLabel label1 = new JLabel("学号:",JLabel.CENTER);
public a(String parameter)
{
super("我是窗体a");
String str=parameter;
this.setBounds(250,80,350,400);
this.setVisible(true);
this.setResizable(false);
this.add(label1);
label1.setText(parameter);
}
}
:
//这是b.java文件
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class b extends JFrame implements ActionListener{
JButton button1=new JButton("显示窗体a");
public b()
{
super("我是窗体b");
this.setBounds(250,80,350,400);
this.setVisible(true);
this.setResizable(false);
button1.setBounds(35,140,70,20);
button1.addActionListener(this);
this.add(button1);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button1)
{
String title ="我是窗体b传过来的值";
new a(title);
}
}
public static void main(String argv[])
{
new b();
}
}
//这是a.java文件
/**
* Created with IntelliJ IDEA.
* User: Administrator
* Date: 12-6-19
* Time: 上午7:31
* To change this template use File | Settings | File Templates.
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class a extends JFrame{
JLabel label1 = new JLabel("学号:",JLabel.CENTER);
public a(String parameter)
{
super("我是窗体a");
String str=parameter;
this.setBounds(250,80,350,400);
this.setVisible(true);
this.setResizable(false);
this.add(label1);
label1.setText(parameter);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询