import java.awt.*;
import javax.swing.*;
import java.awt.event.*;public class TextArea { /**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
TextAreaExample Tae = new TextAreaExample(); }}class TextAreaExample extends JFrame implements ActionListener{
JTextArea area1;
JTextArea area2;
JScrollPane js1;
JScrollPane js2;
JSplitPane jsp;
JButton b1,b2;
JLabel jl1,jl2;
JMenuBar mb;
JMenu mu1,mu2;
JMenuItem itemCopy,itemCut,itemPaste,item4;
JPanel p1;
HelpListen hlisten;
TextAreaExample() { area1 = new JTextArea();
area2 = new JTextArea();
mb=new JMenuBar();
hlisten=new HelpListen();
mu1=new JMenu("编辑");
mu2=new JMenu("帮助");
itemCopy=new JMenuItem("复制");
itemCut=new JMenuItem("剪切");
itemPaste=new JMenuItem("粘贴");
item4=new JMenuItem("关于");
itemCopy.addActionListener(this);
itemCut.addActionListener(this);
itemPaste.addActionListener(this);
item4.addActionListener(hlisten);
mu1.add(itemCopy);
mu1.add(itemCut);
mu1.add(itemPaste);
mu2.add(item4);
mb.add(mu1);
mb.add(mu2);
setJMenuBar(mb);
jl1=new JLabel("明文区");
jl2=new JLabel("密文区");
area1.setLineWrap(true);
area2.setLineWrap(true);
js1 = new JScrollPane(area1);
js2 = new JScrollPane(area2);
jsp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,js1,js2);
add(jsp,BorderLayout.CENTER);
jsp.setDividerLocation(180);
p1 = new JPanel();
b1 = new JButton("加密");
b2 = new JButton("清空");
p1.add(jl1);
p1.add(b1);
p1.add(b2);
p1.add(jl2);
add(p1,BorderLayout.NORTH);
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String str = area1.getText();
char a[]=str.toCharArray();
for(int i=0;i<a.length;i++)
{
a[i]=(char)(a[i]^'a');
}
String str1=new String(a);
//System.out.println(str);
area2.setText(str1);
} });
//b2.add(comp);
setBounds(100, 100, 400, 400);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==itemCopy)
area1.copy();
else if(e.getSource()==itemCut)
area1.cut();
else if(e.getSource()==itemPaste)
area2.paste();
}
}
class HelpListen implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Introduction in=new Introduction();
}
}
class ClearListen implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
area1.setText="";//编译报错 有没有办法在这个类里访问这个临时变量
我不想把所有的监听都写成匿名类的形式,就像这样 b1.addActionListener(new ActionListener()
}
}class Introduction extends JFrame
{
JLabel lab1;
Introduction()
{
lab1=new JLabel("");
add(lab1);
setBounds(200,100,300,240);
setVisible(true);
validate();
}
}
import javax.swing.*;
import java.awt.event.*;public class TextArea { /**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
TextAreaExample Tae = new TextAreaExample(); }}class TextAreaExample extends JFrame implements ActionListener{
JTextArea area1;
JTextArea area2;
JScrollPane js1;
JScrollPane js2;
JSplitPane jsp;
JButton b1,b2;
JLabel jl1,jl2;
JMenuBar mb;
JMenu mu1,mu2;
JMenuItem itemCopy,itemCut,itemPaste,item4;
JPanel p1;
HelpListen hlisten;
TextAreaExample() { area1 = new JTextArea();
area2 = new JTextArea();
mb=new JMenuBar();
hlisten=new HelpListen();
mu1=new JMenu("编辑");
mu2=new JMenu("帮助");
itemCopy=new JMenuItem("复制");
itemCut=new JMenuItem("剪切");
itemPaste=new JMenuItem("粘贴");
item4=new JMenuItem("关于");
itemCopy.addActionListener(this);
itemCut.addActionListener(this);
itemPaste.addActionListener(this);
item4.addActionListener(hlisten);
mu1.add(itemCopy);
mu1.add(itemCut);
mu1.add(itemPaste);
mu2.add(item4);
mb.add(mu1);
mb.add(mu2);
setJMenuBar(mb);
jl1=new JLabel("明文区");
jl2=new JLabel("密文区");
area1.setLineWrap(true);
area2.setLineWrap(true);
js1 = new JScrollPane(area1);
js2 = new JScrollPane(area2);
jsp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,js1,js2);
add(jsp,BorderLayout.CENTER);
jsp.setDividerLocation(180);
p1 = new JPanel();
b1 = new JButton("加密");
b2 = new JButton("清空");
p1.add(jl1);
p1.add(b1);
p1.add(b2);
p1.add(jl2);
add(p1,BorderLayout.NORTH);
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String str = area1.getText();
char a[]=str.toCharArray();
for(int i=0;i<a.length;i++)
{
a[i]=(char)(a[i]^'a');
}
String str1=new String(a);
//System.out.println(str);
area2.setText(str1);
} });
//b2.add(comp);
setBounds(100, 100, 400, 400);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==itemCopy)
area1.copy();
else if(e.getSource()==itemCut)
area1.cut();
else if(e.getSource()==itemPaste)
area2.paste();
}
}
class HelpListen implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Introduction in=new Introduction();
}
}
class ClearListen implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
area1.setText="";//编译报错 有没有办法在这个类里访问这个临时变量
我不想把所有的监听都写成匿名类的形式,就像这样 b1.addActionListener(new ActionListener()
}
}class Introduction extends JFrame
{
JLabel lab1;
Introduction()
{
lab1=new JLabel("");
add(lab1);
setBounds(200,100,300,240);
setVisible(true);
validate();
}
}
解决方案 »
- 存储学员信息,每个学员信息包括学号、姓名、三门课的成绩、平均成绩,能按平均成绩排序输出学员信息。
- 阅读《Java核心开发技术从入门到精通》时,遇到的问题:这个语句是什么意思…(答完追加高分)
- 边界标志算法
- a=a++; 怎么赋值?
- 做了好久都没做出来,请求帮忙!
- swt高手请进,有技术含量,组件在页面移动的问题..急急急!!拜托各位大大了
- 奇怪!!!jdk5的doc里没有AbstractStringBuider这个类?谁能给各解释!!!
- 新手提问???
- 真是越来越弱呀...
- SOS!SOS!SOS!我的页面有VRML场景,同时有javaAPPLET,怎样由场景向APPLET发送消息或交互
- 如何用java实现excel转换成csv
- 请高手帮忙
package CSDNTest;import java.awt.*;
import javax.swing.*;
import java.awt.event.*;public class TextArea { /**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
TextAreaExample Tae = new TextAreaExample(); }}class TextAreaExample extends JFrame implements ActionListener {
private static JTextArea area1;
JTextArea area2;
JScrollPane js1;
JScrollPane js2;
JSplitPane jsp;
JButton b1, b2;
JLabel jl1, jl2;
JMenuBar mb;
JMenu mu1, mu2;
JMenuItem itemCopy, itemCut, itemPaste, item4;
JPanel p1;
HelpListen hlisten;
public static JTextArea getArea1Instance(){
return area1;
} TextAreaExample() { area1 = new JTextArea();
area2 = new JTextArea();
mb = new JMenuBar();
hlisten = new HelpListen();
mu1 = new JMenu("编辑");
mu2 = new JMenu("帮助");
itemCopy = new JMenuItem("复制");
itemCut = new JMenuItem("剪切");
itemPaste = new JMenuItem("粘贴");
item4 = new JMenuItem("关于");
itemCopy.addActionListener(this);
itemCut.addActionListener(this);
itemPaste.addActionListener(this);
item4.addActionListener(hlisten);
mu1.add(itemCopy);
mu1.add(itemCut);
mu1.add(itemPaste);
mu2.add(item4);
mb.add(mu1);
mb.add(mu2);
setJMenuBar(mb);
jl1 = new JLabel("明文区");
jl2 = new JLabel("密文区");
area1.setLineWrap(true);
area2.setLineWrap(true);
js1 = new JScrollPane(area1);
js2 = new JScrollPane(area2);
jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, js1, js2);
add(jsp, BorderLayout.CENTER);
jsp.setDividerLocation(180);
p1 = new JPanel();
b1 = new JButton("加密");
b2 = new JButton("清空");
p1.add(jl1);
p1.add(b1);
p1.add(b2);
p1.add(jl2);
add(p1, BorderLayout.NORTH);
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String str = area1.getText();
char a[] = str.toCharArray();
for (int i = 0; i < a.length; i++) {
a[i] = (char) (a[i] ^ 'a');
}
String str1 = new String(a);
// System.out.println(str);
area2.setText(str1);
} });
// b2.add(comp); setBounds(100, 100, 400, 400);
setVisible(true);
validate();
} public void actionPerformed(ActionEvent e) {
if (e.getSource() == itemCopy)
area1.copy();
else if (e.getSource() == itemCut)
area1.cut();
else if (e.getSource() == itemPaste)
area2.paste();
}
}class HelpListen implements ActionListener {
public void actionPerformed(ActionEvent e) {
Introduction in = new Introduction();
}
}class ClearListen implements ActionListener {
public void actionPerformed(ActionEvent e) {
TextAreaExample.getArea1Instance().setText("");//编译报错 有没有办法在这个类里访问这个临时变量
// 我不想把所有的监听都写成匿名类的形式,
// 就像这样 b1.addActionListener(new ActionListener()
}
}class Introduction extends JFrame {
JLabel lab1; Introduction() {
lab1 = new JLabel("");
add(lab1);
setBounds(200, 100, 300, 240);
setVisible(true);
validate();
}
}
area1.setText="";这句改成TextAreaExample.area1.setText("");
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.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;class TextArea { /**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
TextAreaExample Tae = new TextAreaExample(); } } class TextAreaExample extends JFrame implements ActionListener{
JTextArea area1;
JTextArea area2;
JScrollPane js1;
JScrollPane js2;
JSplitPane jsp;
JButton b1,b2;
JLabel jl1,jl2;
JMenuBar mb;
JMenu mu1,mu2;
JMenuItem itemCopy,itemCut,itemPaste,item4;
JPanel p1;
HelpListen hlisten;
TextAreaExample() { area1 = new JTextArea();
area2 = new JTextArea();
mb=new JMenuBar();
hlisten=new HelpListen();
mu1=new JMenu("编辑");
mu2=new JMenu("帮助");
itemCopy=new JMenuItem("复制");
itemCut=new JMenuItem("剪切");
itemPaste=new JMenuItem("粘贴");
item4=new JMenuItem("关于");
itemCopy.addActionListener(this);
itemCut.addActionListener(this);
itemPaste.addActionListener(this);
item4.addActionListener(hlisten);
mu1.add(itemCopy);
mu1.add(itemCut);
mu1.add(itemPaste);
mu2.add(item4);
mb.add(mu1);
mb.add(mu2);
setJMenuBar(mb);
jl1=new JLabel("明文区");
jl2=new JLabel("密文区");
area1.setLineWrap(true);
area2.setLineWrap(true);
js1 = new JScrollPane(area1);
js2 = new JScrollPane(area2);
jsp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,js1,js2);
add(jsp,BorderLayout.CENTER);
jsp.setDividerLocation(180);
p1 = new JPanel();
b1 = new JButton("加密");
b2 = new JButton("清空");
p1.add(jl1);
p1.add(b1);
p1.add(b2);
p1.add(jl2);
add(p1,BorderLayout.NORTH);
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String str = area1.getText();
char a[]=str.toCharArray();
for(int i=0;i <a.length;i++)
{
a[i]=(char)(a[i]^'a');
}
String str1=new String(a);
//System.out.println(str);
area2.setText(str1);
} });
//b2.add(comp);
setBounds(100, 100, 400, 400);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==itemCopy)
area1.copy();
else if(e.getSource()==itemCut)
area1.cut();
else if(e.getSource()==itemPaste)
area2.paste();
}
} class HelpListen implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Introduction in=new Introduction();
}
} class ClearListen extends TextAreaExample implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
area1.setText("");//编译报错 有没有办法在这个类里访问这个临时变量
}
} class Introduction extends JFrame
{
JLabel lab1;
Introduction()
{
lab1=new JLabel("");
add(lab1);
setBounds(200,100,300,240);
setVisible(true);
validate();
}
}
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.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;class TextArea { /**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
TextAreaExample Tae = new TextAreaExample(); } } class TextAreaExample extends JFrame implements ActionListener{
JTextArea area1;
JTextArea area2;
JScrollPane js1;
JScrollPane js2;
JSplitPane jsp;
JButton b1,b2;
JLabel jl1,jl2;
JMenuBar mb;
JMenu mu1,mu2;
JMenuItem itemCopy,itemCut,itemPaste,item4;
JPanel p1;
HelpListen hlisten;
TextAreaExample() { area1 = new JTextArea();
area2 = new JTextArea();
mb=new JMenuBar();
hlisten=new HelpListen();
mu1=new JMenu("编辑");
mu2=new JMenu("帮助");
itemCopy=new JMenuItem("复制");
itemCut=new JMenuItem("剪切");
itemPaste=new JMenuItem("粘贴");
item4=new JMenuItem("关于");
itemCopy.addActionListener(this);
itemCut.addActionListener(this);
itemPaste.addActionListener(this);
item4.addActionListener(hlisten);
mu1.add(itemCopy);
mu1.add(itemCut);
mu1.add(itemPaste);
mu2.add(item4);
mb.add(mu1);
mb.add(mu2);
setJMenuBar(mb);
jl1=new JLabel("明文区");
jl2=new JLabel("密文区");
area1.setLineWrap(true);
area2.setLineWrap(true);
js1 = new JScrollPane(area1);
js2 = new JScrollPane(area2);
jsp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,js1,js2);
add(jsp,BorderLayout.CENTER);
jsp.setDividerLocation(180);
p1 = new JPanel();
b1 = new JButton("加密");
b2 = new JButton("清空");
p1.add(jl1);
p1.add(b1);
p1.add(b2);
p1.add(jl2);
add(p1,BorderLayout.NORTH);
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String str = area1.getText();
char a[]=str.toCharArray();
for(int i=0;i <a.length;i++)
{
a[i]=(char)(a[i]^'a');
}
String str1=new String(a);
//System.out.println(str);
area2.setText(str1);
} });
//b2.add(comp);
setBounds(100, 100, 400, 400);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==itemCopy)
area1.copy();
else if(e.getSource()==itemCut)
area1.cut();
else if(e.getSource()==itemPaste)
area2.paste();
}
} class HelpListen implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Introduction in=new Introduction();
}
} class ClearListen extends TextAreaExample implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
area1.setText("");//编译报错 有没有办法在这个类里访问这个临时变量
}
} class Introduction extends JFrame
{
JLabel lab1;
Introduction()
{
lab1=new JLabel("");
add(lab1);
setBounds(200,100,300,240);
setVisible(true);
validate();
}
}
和area1.setText("");