用swing做一个小表单。功能如下:
两个框
在一个框中输入内容
点击提交按钮
刚才输入的内容显示在另外一个框中,最好以前输入的内容也保留。
就这么简单,初学者,谢谢!!!
两个框
在一个框中输入内容
点击提交按钮
刚才输入的内容显示在另外一个框中,最好以前输入的内容也保留。
就这么简单,初学者,谢谢!!!
解决方案 »
- freemarker怎么声明一个int变量,然后给这个int变量+1呢,我也测试了很久不行
- 各位大哥如何显示超出屏幕范围的图片
- 使用正则表达式提取网页正文
- 碰到这样的一道面试题,谁能给点思路?
- java操作excel、文本出错时,如何抛出文件哪一行出错??
- 三天之内不解决,我想我是一个不合格的职员,我想我应该辞职去补习一下了,急sql语句问题,求解,在线等
- 谁能解决?10本电子书籍作为报酬 ...
- 帮忙解读一段集合加范型的代码
- 怎样使用GridBagConstraints控制控件的大小?
- 帮我看看下面这段连接SQL server数据库的代码为什么会错啊?
- request.getParameter()
- 局域网多线程下载
package swing;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.SwingUtilities;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class NewJFrame extends javax.swing.JFrame { {
//Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
} catch(Exception e) {
e.printStackTrace();
}
} private JTextArea jTextArea1;
private JButton jButton1;
private JTextArea jTextArea2;
private JPanel jPanel1; /**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
NewJFrame inst = new NewJFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public NewJFrame() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
BorderLayout thisLayout = new BorderLayout();
getContentPane().setLayout(thisLayout);
{
jPanel1 = new JPanel();
getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.setPreferredSize(new java.awt.Dimension(452, 96));
jPanel1.setLayout(null);
{
jTextArea2 = new JTextArea();
jPanel1.add(jTextArea2);
jTextArea2.setBounds(278, 15, 164, 64);
jTextArea2.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
}
{
jButton1 = new JButton();
jPanel1.add(jButton1);
jButton1.setText("\u6dfb\u52a0");
jButton1.setBounds(188, 33, 59, 25);
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
}
{
jTextArea1 = new JTextArea();
jPanel1.add(jTextArea1);
jTextArea1.setBounds(10, 15, 156, 64);
jTextArea1.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
}
}
pack();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jButton1ActionPerformed(ActionEvent evt) {
System.out.println("jButton1.actionPerformed, event="+evt);
//TODO add your code for jButton1.actionPerformed
String text=jTextArea1.getText();
if(text!=null){
jTextArea2.append(text);
}
jTextArea1.setText("");
}}
JTextField tf1 = new JTextField();
JTextField tf2 = new JTextField();
JButton btn = new JButton("submit"); public static void main(String[] args) {
new MyFrame();
}
public MyFrame() {
super("test");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(null);
ft1.setBounds(20, 20, 80, 20);
ft2.setBounds(120, 20, 80, 20);
btn.setBounds(50, 20, 80, 20);
c.add(tf1);
c.add(tf2);
c.add(btn);
btn.addActionListener(new ActionListener() {
tf2.setText(tf1.getText());
});
setVisible(true);
}
}
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tf2.setText(tf1.getText());
}
});
import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;public class Copy extends Frame { Button b;
TextField L, R; public void display() {
Frame f = new Frame("复制");
f.setSize(300, 150);
f.setBackground(Color.lightGray);
f.setLayout(new FlowLayout());
L = new TextField(10);
R = new TextField(10);
b = new Button("复制");
f.add(L);
f.add(R);
f.add(b);
b.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
R.setText(L.getText());
}
});
f.setVisible(true);
} public static void main(String[] args) {
(new Copy()).display();
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;class MyFrame extends JFrame {
JTextField tf1 = new JTextField();
JTextArea ta = new JTextArea();
JButton btn = new JButton("submit"); public static void main(String[] args) {
new MyFrame();
} public MyFrame() {
super("test");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(null);
tf1.setBounds(20, 20, 80, 20);
ta.setBounds(120, 20, 80, 200);
btn.setBounds(20, 200, 80, 20);
c.add(tf1);
c.add(ta);
c.add(btn);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// str = str + "\n" + tf1.getText();
// ta.setText(str);
ta.append(tf1.getText()+ "\n");
}
});
setVisible(true);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;class MyFrame extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
JTextField tf1 = new JTextField();
JTextArea ta = new JTextArea();
JButton btn = new JButton("submit");
public static void main(String[] args) {
new MyFrame();
} public MyFrame() {
super("test");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(null);
ta.setLineWrap(true); //设置自动换行,自动换行则不会出现横向的滚动条
ta.setEditable(true); //设置可编辑
JScrollPane jsp = new JScrollPane(ta);
tf1.setBounds(20, 20, 80, 20);
ta.setBounds(120, 20, 80, 200);
jsp.setBounds(120, 15, 80, 200);
btn.setBounds(10, 200, 80, 20);
//jp.add(jsp);
//c.add(jp);
c.add(jsp);
c.add(tf1);
//c.add(ta);
c.add(btn);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// str = str + "\n" + tf1.getText();
// ta.setText(str);
ta.append(tf1.getText()+ "\n");
}
});
setVisible(true);
}
}