TextArea.select()函数的问题,有时候有用,有时会没用?
packagemm;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclassexol...
package mm;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class exol
{
static JFrame frm = new JFrame();
static JTextArea ta = new JTextArea("此登录号和密码是您再次登录");
static JMenuBar mba = new JMenuBar();
static JMenu m1 = new JMenu("苹果");
static JMenuItem m1_all = new JMenuItem("全选");
static JButton bu=new JButton("您好,这是按钮");
// static JDialog dia=new JDialog(frm,"hello");
public static void main(String[] args)
{
frm.setVisible(true);
frm.setLayout(new FlowLayout());
frm.setBounds(300, 300, 400, 400);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setJMenuBar(mba);
frm.add(ta);
frm.add(bu);
mba.add(m1);
m1.add(m1_all);
m1_all.addActionListener(new Myaction());
bu.addActionListener(new Myaction2());
}
static class Myaction implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
ta.selectAll();
}
}
static class Myaction2 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.out.println("OK");
ta.selectAll();
}
}
}
刚开始运行的使用,点JMenuItem有用,在点了按钮之后就没用了,按理说点按钮应该也能全选,为什么不行,这个问题我一只郁闷很久了,谢谢 展开
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class exol
{
static JFrame frm = new JFrame();
static JTextArea ta = new JTextArea("此登录号和密码是您再次登录");
static JMenuBar mba = new JMenuBar();
static JMenu m1 = new JMenu("苹果");
static JMenuItem m1_all = new JMenuItem("全选");
static JButton bu=new JButton("您好,这是按钮");
// static JDialog dia=new JDialog(frm,"hello");
public static void main(String[] args)
{
frm.setVisible(true);
frm.setLayout(new FlowLayout());
frm.setBounds(300, 300, 400, 400);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setJMenuBar(mba);
frm.add(ta);
frm.add(bu);
mba.add(m1);
m1.add(m1_all);
m1_all.addActionListener(new Myaction());
bu.addActionListener(new Myaction2());
}
static class Myaction implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
ta.selectAll();
}
}
static class Myaction2 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.out.println("OK");
ta.selectAll();
}
}
}
刚开始运行的使用,点JMenuItem有用,在点了按钮之后就没用了,按理说点按钮应该也能全选,为什么不行,这个问题我一只郁闷很久了,谢谢 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询