STEP #1

(1/2)

此处切换ai服务商,可对比多家ai的回复,取最优解。

上一步下一步关闭
酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

编写一个程序,窗口的标题为“myframe”,窗口的布局为flowlayout布局,窗口大小为400*300像素,位置距离屏幕左上角(100,100)像素。界面上有两个文本框,文本框前面的标签分别为“输入:”,“结果:”,另外还有两个按钮,分别为“copy”和“close”,当按“copy”按钮时将第一个文本框的内容复制到第二个文本框;当按“close”按钮时则结束程序的运行。用java编写

以下是一个使用 Java 编写的满足您需求的示例程序: ```java import java.awt.FlowLayout; 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.JTextField; public class MyFrame extends JFrame { private JTextField inputTextField; private JTextField resultTextField; public MyFrame() { setTitle("myframe"); setSize(400, 300); setLocation(100, 100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout()); JLabel inputLabel = new JLabel("输入:"); add(inputLabel); inputTextField = new JTextField(20); add(inputTextField); JLabel resultLabel = new JLabel("结果:"); add(resultLabel); resultTextField = new JTextField(20); add(resultTextField); JButton copyButton = new JButton("copy"); copyButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String text = inputTextField.getText(); resultTextField.setText(text); } }); add(copyButton); JButton closeButton = new JButton("close"); closeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); add(closeButton); } public static void main(String[] args) { MyFrame frame = new MyFrame(); frame.setVisible(true); } } ``` [2024-11-12 14:15:28 | AI写代码神器 | 385点数解答]

相关提问