package lx2;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Strlj extends JFrame implements ActionListener{
private JTextField s1,s2,sResult;
private JLabel l1,l2,l3;
private JButton btn;
{
JFrame frame=new JFrame("字符串连接");
l1=new JLabel("字符串1");
s1=new JTextField(5);
l2=new JLabel("字符串2");
s2=new JTextField(5);
l3=new JLabel("结果:");
sResult=new JTextField(7);
btn=new JButton("连接");
frame.setLayout(new FlowLayout());
frame.add(l1);
frame.add(s1);
frame.add(l2);
frame.add(s2);
frame.add(btn);
btn.addActionListener(this);
frame.add(l3);
frame.add(sResult);
frame.setSize(540,120);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String str1=s1.getText();
String str2=s2.getText();
sResult.setText(str1+str2);
}
public static void main(String[] args) {
Strlj lj=new Strlj();
}
}
Java两个字符串的连接
最新推荐文章于 2023-03-18 22:09:52 发布