java 怎么加入滚动条
importjava.awt.*;importjava.io.*;importjava.awt.event.*;importjavax.swing.*;publiccla...
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
public class jj extends JFrame implements ActionListener{
JMenuBar cd;
JMenu cd1,cd2;
JMenuItem cd3,cd4;
JTextArea wby;
JScrollPane gd;
public static void main(String[] args)throws Exception{
jj a=new jj( );
}
public jj(){
cd=new JMenuBar();
cd1=new JMenu("文件");
cd2=new JMenu("编辑");
cd3=new JMenuItem("打开");
cd4=new JMenuItem("保存");
wby=new JTextArea();
gd=new JScrollPane();
cd1.add(cd3); cd1.add(cd4); cd.add(cd1); cd.add(cd2);
this.setJMenuBar(cd); this.add(wby,BorderLayout.CENTER);
cd3.addActionListener(this);
cd3.setActionCommand("open");
cd4.addActionListener(this);
cd4.setActionCommand("cloce");
this.setTitle(" ");
// this.setResizable(false);
this.setSize(500,500);
this.setLocation(500,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("open")){
JFileChooser wjxz=new JFileChooser();
wjxz.setDialogTitle("打开");
wjxz.showOpenDialog(null);
wjxz.setVisible(true);
String wjlj=wjxz.getSelectedFile().getAbsolutePath();
FileReader wjl=null; BufferedReader zhl=null;
try{
wjl=new FileReader(wjlj);
zhl=new BufferedReader(wjl);
String aa="",bb="";
while((aa=zhl.readLine())!=null){
bb+=(aa+"\n");
}
wby.setText(bb); //怎么加入滚动条
}catch(Exception e1){}
finally{
try {
zhl.close();
wjl.close();
} catch (Exception e1) {
}
}
}
}
} 展开
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
public class jj extends JFrame implements ActionListener{
JMenuBar cd;
JMenu cd1,cd2;
JMenuItem cd3,cd4;
JTextArea wby;
JScrollPane gd;
public static void main(String[] args)throws Exception{
jj a=new jj( );
}
public jj(){
cd=new JMenuBar();
cd1=new JMenu("文件");
cd2=new JMenu("编辑");
cd3=new JMenuItem("打开");
cd4=new JMenuItem("保存");
wby=new JTextArea();
gd=new JScrollPane();
cd1.add(cd3); cd1.add(cd4); cd.add(cd1); cd.add(cd2);
this.setJMenuBar(cd); this.add(wby,BorderLayout.CENTER);
cd3.addActionListener(this);
cd3.setActionCommand("open");
cd4.addActionListener(this);
cd4.setActionCommand("cloce");
this.setTitle(" ");
// this.setResizable(false);
this.setSize(500,500);
this.setLocation(500,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("open")){
JFileChooser wjxz=new JFileChooser();
wjxz.setDialogTitle("打开");
wjxz.showOpenDialog(null);
wjxz.setVisible(true);
String wjlj=wjxz.getSelectedFile().getAbsolutePath();
FileReader wjl=null; BufferedReader zhl=null;
try{
wjl=new FileReader(wjlj);
zhl=new BufferedReader(wjl);
String aa="",bb="";
while((aa=zhl.readLine())!=null){
bb+=(aa+"\n");
}
wby.setText(bb); //怎么加入滚动条
}catch(Exception e1){}
finally{
try {
zhl.close();
wjl.close();
} catch (Exception e1) {
}
}
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询