java图形界面程序,当单击按钮时把一个文本框当前内容复制到另一个文本框中?
展开全部
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Main extends JFrame {
private JTextArea text1 = null;
private JTextArea text2 = null;
private JButton copyButton = null;
public Main() {
super("测试");
init();
JPanel pane = new JPanel(null);
getContentPane().add(pane);
JScrollPane s1 = new JScrollPane(text1);
JScrollPane s2 = new JScrollPane(text2);
pane.add(s1);
pane.add(s2);
s1.setBounds(10, 10, 200, 300);
s2.setBounds(260, 10, 200, 300);
getContentPane().add(copyButton, BorderLayout.SOUTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(480, 380);
setLocationRelativeTo(null);
setVisible(true);
}
/**
* 初始化组件对象
*/
private void init(){
text1 = new JTextArea();
text2 = new JTextArea();
copyButton = new JButton("复制");
copyButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
copy();
}
});
}
private void copy(){
text2.setText(text1.getText());
}
public static void main(String[] args) {
new Main();
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Main extends JFrame {
private JTextArea text1 = null;
private JTextArea text2 = null;
private JButton copyButton = null;
public Main() {
super("测试");
init();
JPanel pane = new JPanel(null);
getContentPane().add(pane);
JScrollPane s1 = new JScrollPane(text1);
JScrollPane s2 = new JScrollPane(text2);
pane.add(s1);
pane.add(s2);
s1.setBounds(10, 10, 200, 300);
s2.setBounds(260, 10, 200, 300);
getContentPane().add(copyButton, BorderLayout.SOUTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(480, 380);
setLocationRelativeTo(null);
setVisible(true);
}
/**
* 初始化组件对象
*/
private void init(){
text1 = new JTextArea();
text2 = new JTextArea();
copyButton = new JButton("复制");
copyButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
copy();
}
});
}
private void copy(){
text2.setText(text1.getText());
}
public static void main(String[] args) {
new Main();
}
}
展开全部
private javax.swing.JTextField TXT_A;
private javax.swing.JTextField TXT_B;
this.TXT_B.setText(this.TXT_A.getText());
private javax.swing.JTextField TXT_B;
this.TXT_B.setText(this.TXT_A.getText());
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;
import java.util.Date;
public class Form1 extends Form
{
Date today=new Date();
String []day=;
public Form1()
{
// Required for Visual J++ Form Designer support
initForm();
// TODO: Add any constructor code after initForm call
}
public void dispose()
{
super.dispose();
components.dispose();
}
private void button1_click(Object source, Event e)
{
edit1.setText(String.valueOf(today.getYear()+1900)+"年");
}
private void button2_click(Object source, Event e)
{
edit2.setText(String.valueOf(today.getMonth()+1)+"月");
}
private void button3_click(Object source, Event e)
{
edit3.setText(day[today.getDay()]);
}
private void button4_click(Object source, Event e)
{
edit4.setText(String.valueOf(today.getDate())+"日");
}
Container components = new Container();
Edit edit1 = new Edit();
Edit edit2 = new Edit();
Edit edit3 = new Edit();
Edit edit4 = new Edit();
Button button1 = new Button();
Button button2 = new Button();
Button button3 = new Button();
Button button4 = new Button();
private void initForm()
{
this.setText("显示时间");
this.setAutoScaleBaseSize(new Point(6, 12));
this.setClientSize(new Point(463, 158));
this.setStartPosition(FormStartPosition.CENTER_SCREEN);
edit1.setLocation(new Point(40, 48));
edit1.setSize(new Point(88, 19));
edit1.setTabIndex(3);
edit1.setText("");
edit2.setLocation(new Point(136, 48));
edit2.setSize(new Point(88, 19));
edit2.setTabIndex(2);
edit2.setText("");
edit3.setLocation(new Point(232, 48));
edit3.setSize(new Point(88, 19));
edit3.setTabIndex(1);
edit3.setText("");
edit4.setLocation(new Point(328, 48));
edit4.setSize(new Point(88, 19));
edit4.setTabIndex(0);
edit4.setText("");
button1.setLocation(new Point(40, 80));
button1.setSize(new Point(88, 24));
button1.setTabIndex(7);
button1.setText("年份");
button1.addOnClick(new EventHandler(this.button1_click));
button2.setLocation(new Point(136, 80));
button2.setSize(new Point(88, 24));
button2.setTabIndex(6);
button2.setText("月份");
button2.addOnClick(new EventHandler(this.button2_click));
button3.setLocation(new Point(232, 80));
button3.setSize(new Point(88, 24));
button3.setTabIndex(5);
button3.setText("星期");
button3.addOnClick(new EventHandler(this.button3_click));
button4.setLocation(new Point(328, 80));
button4.setSize(new Point(88, 24));
button4.setTabIndex(4);
button4.setText("日期");
button4.addOnClick(new EventHandler(this.button4_click));
this.setNewControls(new Control[] {
button4,
button3,
button2,
button1,
edit4,
edit3,
edit2,
edit1});
}
public static void main(String args[])
{
Application.run(new Form1());
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询