java简单问题
(1)importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclasstest2{publi...
(1)import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test2{
public static void main(String[] s){
aaa a=new aaa();
a.xxx();
}
}
class aaa
{
public JFrame f;
public JButton btn;
public JTextField t1,t2;
public void xxx()
{
f = new JFrame("第二个程序");
Container p = f.getContentPane(); //p是f窗体的内容面板
p.setLayout(new FlowLayout());
btn = new JButton("确定");
t1= new JTextField(10);
t2= new JTextField(10);
p.add(btn);
btn.addActionListener(new handler(this)); //为btn注册事件监听者new ButtonHandler()
//t1.addActionListener(new handler(this));
p.add(t1);
p.add(t2);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocation(100, 300);
f.setSize(300,300);
f.show();
}
}
class handler implements ActionListener
{
aaa h;
public handler(aaa h) {this.h=h;}
public void actionPerformed(ActionEvent e)
{
JTextField textSource=(JTextField)e.getSource();
if((h.btn.getText().equals("来按我"))||(textSource==h.t1))
{ h.t2.setText(h.t1.getText());
/*String c=h.t1.getText();
h.t2.setText(new String(c));*/}
}
}
程序是在t1文本框输入一个字符串按回车或单击按钮,在t2文本框中按逆序显示t1文本框中的字符串
请高手把帮忙调式,谢谢啦 展开
import java.awt.event.*;
import javax.swing.*;
public class test2{
public static void main(String[] s){
aaa a=new aaa();
a.xxx();
}
}
class aaa
{
public JFrame f;
public JButton btn;
public JTextField t1,t2;
public void xxx()
{
f = new JFrame("第二个程序");
Container p = f.getContentPane(); //p是f窗体的内容面板
p.setLayout(new FlowLayout());
btn = new JButton("确定");
t1= new JTextField(10);
t2= new JTextField(10);
p.add(btn);
btn.addActionListener(new handler(this)); //为btn注册事件监听者new ButtonHandler()
//t1.addActionListener(new handler(this));
p.add(t1);
p.add(t2);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocation(100, 300);
f.setSize(300,300);
f.show();
}
}
class handler implements ActionListener
{
aaa h;
public handler(aaa h) {this.h=h;}
public void actionPerformed(ActionEvent e)
{
JTextField textSource=(JTextField)e.getSource();
if((h.btn.getText().equals("来按我"))||(textSource==h.t1))
{ h.t2.setText(h.t1.getText());
/*String c=h.t1.getText();
h.t2.setText(new String(c));*/}
}
}
程序是在t1文本框输入一个字符串按回车或单击按钮,在t2文本框中按逆序显示t1文本框中的字符串
请高手把帮忙调式,谢谢啦 展开
展开全部
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class test2{
public static void main(String[] args){
aaa a=new aaa();
a.xxx();
}
}
class aaa
{
public JFrame f;
public JButton btn;
public JTextField t1,t2;
public void xxx()
{
f = new JFrame("第二个程序");
Container p = f.getContentPane(); //p是f窗体的内容面板
p.setLayout(new FlowLayout());
btn = new JButton("确定");
t1= new JTextField(10);
t2= new JTextField(10);
p.add(btn);
btn.addActionListener(new handler(this)); //为btn注册事件监听者new ButtonHandler()
//t1.addActionListener(new handler(this));
p.add(t1);
p.add(t2);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocation(100, 300);
f.setSize(300,300);
f.show();
}
}
class handler implements ActionListener
{
aaa h;
public handler(aaa h) {this.h=h;}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==h.btn)
{ String tagit = h.t1.getText();
StringBuffer sb = new StringBuffer();
for(int i=tagit.length()-1;i>=0;i--){
System.out.println(i);
char c = tagit.charAt(i);
sb.append(c);
}
h.t2.setText(sb.toString());
}
}
}
功能实现了,你看看吧··
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class test2{
public static void main(String[] args){
aaa a=new aaa();
a.xxx();
}
}
class aaa
{
public JFrame f;
public JButton btn;
public JTextField t1,t2;
public void xxx()
{
f = new JFrame("第二个程序");
Container p = f.getContentPane(); //p是f窗体的内容面板
p.setLayout(new FlowLayout());
btn = new JButton("确定");
t1= new JTextField(10);
t2= new JTextField(10);
p.add(btn);
btn.addActionListener(new handler(this)); //为btn注册事件监听者new ButtonHandler()
//t1.addActionListener(new handler(this));
p.add(t1);
p.add(t2);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocation(100, 300);
f.setSize(300,300);
f.show();
}
}
class handler implements ActionListener
{
aaa h;
public handler(aaa h) {this.h=h;}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==h.btn)
{ String tagit = h.t1.getText();
StringBuffer sb = new StringBuffer();
for(int i=tagit.length()-1;i>=0;i--){
System.out.println(i);
char c = tagit.charAt(i);
sb.append(c);
}
h.t2.setText(sb.toString());
}
}
}
功能实现了,你看看吧··
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询