| 网站首页 | 业界新闻 | 群组 | 人才 | 技术文章 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 436 人关注过本帖
标题:【求助】这个Java中的图形界面程序哪里出错了??
只看楼主 收藏
本帖由 renkejun1942 于 2017-5-25 12:39 移动
汪小贱
Rank: 2
等 级:论坛游民
帖 子:24
专家分:36
注 册:2017-1-23
结帖率:83.33%
  问题点数:0  回复次数:7   
【求助】这个Java中的图形界面程序哪里出错了??
package name1;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
//4)    编写图形界面的程序,接收用户输入的一个字符串和一个字符,将字符串中的所有该字符删除,打印输出新生成的结果字符串。
public class Picture extends Applet implements ActionListener
{
    Label prompt1;
    Label prompt2;
    TextField input1;
    TextField input2;
    //double d=0.0;
    //char []a=new char[100];
    String d="null";
    public void init()
    {
        prompt1=new Label("请输入一个字符串以及一个字符:");
        
        prompt2=new Label("+");
        input1=new TextField(10);
        input2=new TextField(5);
        add(prompt1);
        add(input1);
        add(prompt2);
        add(input2);
        input1.addActionListener(this);
        input2.addActionListener(this);
    }
    public void paint(Graphics g)
    {
        //String d=a.toString();
        g.drawString("最终输出的字符串为:"+d, 10, 50);//10,50是控制x,y的坐标的,在这里控制的是“你输入了数据”这句话的位置
    }
    public void actionPerformed(ActionEvent e)
    {
        char []a=new char[100];
        String b=input1.toString();
        String c=input2.toString();
        char []c1=c.toCharArray();
        char []ch=b.toCharArray();
        int i=0;
        int j=0;
        do{
            if(ch[i]==c1[0])
            {
                i++;
                continue;
            }
            else
            {
                a[j]=ch[i];
                i++;
                j++;
            }
        }while(i<b.length());
        d=a.toString();
        repaint( );
    }
}
搜索更多相关主题的帖子: package  字符串  import  double  public  
2017-05-25 09:06
zsh981022984
Rank: 3Rank: 3
来 自:湖南
等 级:论坛游侠
威 望:6
帖 子:36
专家分:153
注 册:2015-12-6
  得分:0 
回复 楼主 汪小贱
是有错误还是功能无法实现

因为有了因为,所以有了所以,既然已成既然,何必再说何必
2017-05-25 16:34
kaosaier
Rank: 4
等 级:业余侠客
威 望:7
帖 子:120
专家分:298
注 册:2016-7-23
  得分:0 
回复 楼主 汪小贱
package name1;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
//4)&nbsp;&nbsp;&nbsp; 编写图形界面的程序,接收用户输入的一个字符串和一个字符,将字符串中的所有该字符删除,打印输出新生成的结果字符串。
public class Picture extends Applet implements ActionListener
{
&nbsp;&nbsp;&nbsp; Label prompt1;
&nbsp;&nbsp;&nbsp; Label prompt2;
&nbsp;&nbsp;&nbsp; TextField input1;
&nbsp;&nbsp;&nbsp; TextField input2;
&nbsp;&nbsp;&nbsp; //double d=0.0;
&nbsp;&nbsp;&nbsp; //char []a=new char[100];
&nbsp;&nbsp;&nbsp; String d="null";
&nbsp;&nbsp;&nbsp; public void init()
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prompt1=new Label("请输入一个字符串以及一个字符:");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prompt2=new Label("+");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;input1=new TextField(10);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;input2=new TextField(5);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        add(prompt1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add(input1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add(prompt2);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add(input2);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

        input1.addActionListener(this);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;input2.addActionListener(this);
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; public void paint(Graphics g)
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//String d=a.toString();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g.drawString("最终输出的字符串为:"+d, 10, 50);//10,50是控制x,y的坐标的,在这里控制的是“你输入了数据”这句话的位置
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; public void actionPerformed(ActionEvent e)
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char []a=new char[100];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String b=input1.toString();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String c=input2.toString();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char []c1=c.toCharArray();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char []ch=b.toCharArray();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int i=0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int j=0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(ch[i]==c1[0])
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i++;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a[j]=ch[i];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i++;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j++;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}while(i<b.length());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d=a.toString();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;repaint( );
&nbsp;&nbsp;&nbsp; }
}

minecraft,我的最爱!
2017-05-25 17:53
汪小贱
Rank: 2
等 级:论坛游民
帖 子:24
专家分:36
注 册:2017-1-23
  得分:0 
回复 2楼 zsh981022984
功能无法实现
2017-05-31 20:16
汪小贱
Rank: 2
等 级:论坛游民
帖 子:24
专家分:36
注 册:2017-1-23
  得分:0 
回复 3楼 kaosaier
不对啊,最终显示的结果是乱码啊
2017-05-31 20:17
林月儿
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:湖南
等 级:版主
威 望:71
帖 子:1366
专家分:5758
注 册:2015-3-19
  得分:0 
程序代码:
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.JTextArea;
import javax.swing.JTextField;

public class Test {
    JFrame jframe = new JFrame("Test");
    JTextArea jta = new JTextArea();
    JButton button = new JButton("handle");
    JTextField jtfMain = new JTextField(20);
    JTextField jtfSet = new JTextField(2);
    {
        jframe.add(jta, BorderLayout.CENTER);
        JPanel panSou = new JPanel();
        jframe.add(panSou, BorderLayout.SOUTH);
        panSou.add(jtfMain);
        panSou.add(jtfSet);
        panSou.add(button);
        button.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                jta.setText(jtfMain.getText().replace(jtfSet.getText(), ""));
            }
        });
        jframe.setSize(420, 200);
        jframe.setLocation(400, 300);
        jframe.setVisible(true);
    }
    public static void main(String[] args) {
        new Test();
    }
}

like wind.
2017-05-31 22:24
LG隐
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:50
专家分:118
注 册:2016-4-20
  得分:0 
package name1;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
//4)    编写图形界面的程序,接收用户输入的一个字符串和一个字符,将字符串中的所有该字符删除,打印输出新生成的结果字符串。
public class Picture extends Applet implements ActionListener
{
    Label prompt1;
    Label prompt2;
    TextField input1;
    TextField input2;
    //double d=0.0;
    //char []a=new char[100];
   
    String d="null";
    public void init()
    {
        prompt1=new Label("请输入一个字符串以及一个字符:");
        
        prompt2=new Label("+");
        input1=new TextField(10);
        input2=new TextField(5);
        add(prompt1);
        add(input1);
        add(prompt2);
        add(input2);
        input1.addActionListener(this);
        input2.addActionListener(this);
    }
    public void paint(Graphics g)
    {
        //String d=a.toString();
        g.drawString("最终输出的字符串为:"+d, 10, 50);//10,50是控制x,y的坐标的,在这里控制的是“你输入了数据”这句话的位置
    }
    public void actionPerformed(ActionEvent e)
    {
       char []a=new char[100];
        String b=input1.getText();//用这个函数获取输入内容
        String c=input2.getText();//
        char []c1=c.toCharArray();
        char []ch=b.toCharArray();
        int i=0;
        int j=0;
        do{
            if(ch[i]==c1[0])
            {
                i++;
                continue;
            }
            else
            {
                a[j]=ch[i];
                i++;
                j++;
            }
        }while(i<b.length());
        d=String.valueOf( a);   //toString()得到的是[类型@哈希值]
        repaint( );
    }
}
2017-05-31 22:46
LG隐
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:50
专家分:118
注 册:2016-4-20
  得分:0 
这是调用的toString()函数
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}

http://www.cnblogs.com/ningvsban/p/3955483.html
2017-05-31 22:48







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.054892 second(s), 9 queries.
Copyright©2004-2017, BCCN.NET, All Rights Reserved