Java 急急 菜单栏显示不出来
importjava.awt.*;importjavax.swing.*;importjavax.swing.text.JTextComponent;importjava...
import java.awt.*;
import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.awt.event.*;
import java.io.*;
@SuppressWarnings("serial")
public class caidan extends JFrame implements ActionListener{
JTextArea txa=new JTextArea (8,14);
JMenuBar mb=new JMenuBar();
JMenu menuo =new JMenu();
JMenuItem mi1_1 =new JMenuItem("打开");
JMenuItem mi1_2 =new JMenuItem("保存");
JMenuItem mi1_3 =new JMenuItem("退出");
public caidan()
{
super("编辑页");
JPanel jp=new JPanel();
jp.setLayout(new FlowLayout());
jp.add(txa);
menuo.add(mi1_1);
menuo.add(mi1_2);
menuo.add(mi1_3);
mi1_1.addActionListener(this);
mi1_2.addActionListener(this);
mi1_3.addActionListener(this);
mb.add(menuo);
this.setContentPane(jp);
this.setSize(300, 150);
this.setJMenuBar(mb);
this.setVisible(true);
}
public static void main(String arg[])throws IOException{
caidan frm=new caidan();
}
public void actionPerformed(ActionEvent e, JTextComponent outStream) throws IOException {
// TODO Auto-generated method stub
JMenuItem mi=(JMenuItem)e.getSource();
if(mi==mi1_1)
{ String str="";
File inFile = new File("f:\\1.txt");
FileInputStream inStream = new FileInputStream(inFile);
for(int i=inStream.read();i!=-1;i=inStream.read())
str+=(char)i;
txa.setText(str);
}
if(mi==mi1_2)
{System.exit(0);}
else
{String str=txa.getText() ;
FileOutputStream f=new FileOutputStream("f:\\1.txt");
BufferedOutputStream b=new BufferedOutputStream (f);
byte[] ob=new byte[str.length()];
str.getBytes(0, ob.length, ob, 0);
b.write(ob,0,ob.length);
b.flush();
b.close();
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
} 展开
import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.awt.event.*;
import java.io.*;
@SuppressWarnings("serial")
public class caidan extends JFrame implements ActionListener{
JTextArea txa=new JTextArea (8,14);
JMenuBar mb=new JMenuBar();
JMenu menuo =new JMenu();
JMenuItem mi1_1 =new JMenuItem("打开");
JMenuItem mi1_2 =new JMenuItem("保存");
JMenuItem mi1_3 =new JMenuItem("退出");
public caidan()
{
super("编辑页");
JPanel jp=new JPanel();
jp.setLayout(new FlowLayout());
jp.add(txa);
menuo.add(mi1_1);
menuo.add(mi1_2);
menuo.add(mi1_3);
mi1_1.addActionListener(this);
mi1_2.addActionListener(this);
mi1_3.addActionListener(this);
mb.add(menuo);
this.setContentPane(jp);
this.setSize(300, 150);
this.setJMenuBar(mb);
this.setVisible(true);
}
public static void main(String arg[])throws IOException{
caidan frm=new caidan();
}
public void actionPerformed(ActionEvent e, JTextComponent outStream) throws IOException {
// TODO Auto-generated method stub
JMenuItem mi=(JMenuItem)e.getSource();
if(mi==mi1_1)
{ String str="";
File inFile = new File("f:\\1.txt");
FileInputStream inStream = new FileInputStream(inFile);
for(int i=inStream.read();i!=-1;i=inStream.read())
str+=(char)i;
txa.setText(str);
}
if(mi==mi1_2)
{System.exit(0);}
else
{String str=txa.getText() ;
FileOutputStream f=new FileOutputStream("f:\\1.txt");
BufferedOutputStream b=new BufferedOutputStream (f);
byte[] ob=new byte[str.length()];
str.getBytes(0, ob.length, ob, 0);
b.write(ob,0,ob.length);
b.flush();
b.close();
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询