java事件处理如何将单击鼠标值添加到文本框 5
importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.event.*...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class J_Table extends JFrame{
public static final int WIDTH = 400;
public static final int HEIGHT = 250;
public static final String checkedLabel="";
private JTextField countertext;
private JButton counterbutton;
JTextField boardout;
String s;
public J_Table()
{
super("计算器");
setSize(WIDTH, HEIGHT);
Container c =getContentPane();
c.setLayout(new GridLayout());
//建立容纳操作的面板
JPanel buttonPanel = new JPanel();
int i;
for(i=0;i<10;i++)
{
s=""+i;
counterbutton=new JButton(s);
buttonPanel.add(counterbutton);
c.add(buttonPanel);
}
counterbutton=new JButton("=");
buttonPanel.add(counterbutton);
c.add(buttonPanel);
counterbutton=new JButton("c");
buttonPanel.add(counterbutton);
c.add(buttonPanel);
counterbutton=new JButton(" +");
buttonPanel.add(counterbutton);
c.add(buttonPanel);
counterbutton=new JButton(" -");
buttonPanel.add(counterbutton);
c.add(buttonPanel);
counterbutton=new JButton(" * ");
buttonPanel.add(counterbutton);
c.add(buttonPanel);
counterbutton=new JButton(" /");
buttonPanel.add(counterbutton);
c.add(buttonPanel);
JPanel textPanel = new JPanel();
//新建文本区
countertext = new JTextField(checkedLabel,10);
textPanel.add(countertext);
c.add(textPanel);
//用匿名类来实现按钮动作
JButton n = new JButton();
n.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
char a ='0';
String v =String.valueOf(a);
if(a!='='&&a!='c')
{
JTextField boardout=(JTextField)e.getSource();
countertext.setText(v);
}
else
{
}
}
}
);
}
}
这是我的程序,请高手指教! 展开
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class J_Table extends JFrame{
public static final int WIDTH = 400;
public static final int HEIGHT = 250;
public static final String checkedLabel="";
private JTextField countertext;
private JButton counterbutton;
JTextField boardout;
String s;
public J_Table()
{
super("计算器");
setSize(WIDTH, HEIGHT);
Container c =getContentPane();
c.setLayout(new GridLayout());
//建立容纳操作的面板
JPanel buttonPanel = new JPanel();
int i;
for(i=0;i<10;i++)
{
s=""+i;
counterbutton=new JButton(s);
buttonPanel.add(counterbutton);
c.add(buttonPanel);
}
counterbutton=new JButton("=");
buttonPanel.add(counterbutton);
c.add(buttonPanel);
counterbutton=new JButton("c");
buttonPanel.add(counterbutton);
c.add(buttonPanel);
counterbutton=new JButton(" +");
buttonPanel.add(counterbutton);
c.add(buttonPanel);
counterbutton=new JButton(" -");
buttonPanel.add(counterbutton);
c.add(buttonPanel);
counterbutton=new JButton(" * ");
buttonPanel.add(counterbutton);
c.add(buttonPanel);
counterbutton=new JButton(" /");
buttonPanel.add(counterbutton);
c.add(buttonPanel);
JPanel textPanel = new JPanel();
//新建文本区
countertext = new JTextField(checkedLabel,10);
textPanel.add(countertext);
c.add(textPanel);
//用匿名类来实现按钮动作
JButton n = new JButton();
n.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
char a ='0';
String v =String.valueOf(a);
if(a!='='&&a!='c')
{
JTextField boardout=(JTextField)e.getSource();
countertext.setText(v);
}
else
{
}
}
}
);
}
}
这是我的程序,请高手指教! 展开
4个回答
展开全部
对界面的鼠标事件进行处理
将鼠标点击次数保存后 传入到文本框
将鼠标点击次数保存后 传入到文本框
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
MouseListener ml = new MouseListener(){
public void mouseClicked(MouseEvent e){
System.out.println("Mouse clicked.");
}
......
};
boardout.addMouseListener(ml);
你的问题不太明确,没理解。
public void mouseClicked(MouseEvent e){
System.out.println("Mouse clicked.");
}
......
};
boardout.addMouseListener(ml);
你的问题不太明确,没理解。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
jb 就简单了,判断是哪个按钮被按下
然后,做相应的处理就可以了
然后,做相应的处理就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
长
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |