展开全部
程序如下:
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class FrameShow extends JFrame implements ActionListener
{
private JTextField textField;
private JButton button;
private JLabel label;
private JPanel panel;
public FrameShow()
{
textField = new JTextField(18);
button = new JButton("显示内容");
label = new JLabel("",JLabel.CENTER);
panel = new JPanel();
setLayout(new BorderLayout());
setBounds((Toolkit.getDefaultToolkit().getScreenSize().width - 500)/2,
(Toolkit.getDefaultToolkit().getScreenSize().height - 400)/2, 500, 400);
panel.setLayout(new FlowLayout());
panel.add(textField);
panel.add(button);
add(panel,BorderLayout.NORTH);
add(label,BorderLayout.CENTER);
setResizable(false);
setVisible(true);
this.button.addActionListener(this);
}
public static void main(String[] args)
{
new FrameShow();
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == button)
{
this.label.setText(this.textField.getText());
}
}
}
有问题欢迎提问,满意请采纳,谢谢!
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class FrameShow extends JFrame implements ActionListener
{
private JTextField textField;
private JButton button;
private JLabel label;
private JPanel panel;
public FrameShow()
{
textField = new JTextField(18);
button = new JButton("显示内容");
label = new JLabel("",JLabel.CENTER);
panel = new JPanel();
setLayout(new BorderLayout());
setBounds((Toolkit.getDefaultToolkit().getScreenSize().width - 500)/2,
(Toolkit.getDefaultToolkit().getScreenSize().height - 400)/2, 500, 400);
panel.setLayout(new FlowLayout());
panel.add(textField);
panel.add(button);
add(panel,BorderLayout.NORTH);
add(label,BorderLayout.CENTER);
setResizable(false);
setVisible(true);
this.button.addActionListener(this);
}
public static void main(String[] args)
{
new FrameShow();
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == button)
{
this.label.setText(this.textField.getText());
}
}
}
有问题欢迎提问,满意请采纳,谢谢!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |