2个回答
展开全部
package myclass;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import com.sun.tools.hat.internal.parser.Reader;
public class MyTxt extends JFrame implements ActionListener
{
JTextArea ta;
JMenuItem open,save,myexit,open1,save1;
JMenuItem copy,palse;
JMenuBar mb;
JPopupMenu popm;
JScrollPane sp;
public void createmenu()
{
mb=new JMenuBar();
JMenu m1=new JMenu("文件");
JMenu m2=new JMenu("编辑");
JMenu m3=new JMenu("字体");
mb.add(m1);mb.add(m2);m2.add(m3);
open=new JMenuItem("打开");
//ImageIcon ii = new ImageIcon("a.gif");
//open.setIcon(new ImageIcon("b.gif"));
open.addActionListener(this);
save=new JMenuItem("保存");
save.addActionListener(this);
myexit=new JMenuItem("退出");
myexit.addActionListener(this);
m1.add(open);m1.add(save);m1.add(myexit);
copy=new JMenuItem("复制");
palse=new JMenuItem("粘贴");
m2.add(copy);m2.add(palse);
popm=new JPopupMenu ();
open1=new JMenuItem("打开");
open1.addActionListener(this);
save1=new JMenuItem("保存");
save1.addActionListener(this);
popm.add(open1);popm.add(save1);
ta.add(popm);
ta.addMouseListener(new MyMouseEvent(this));
}
class MyMouseEvent extends MouseAdapter
{
MyTxt myparentFrame;
MyMouseEvent ( MyTxt m)
{
myparentFrame=m;
}
public void mouseReleased(MouseEvent e)
{
if(e.isPopupTrigger())
myparentFrame.popm.show((Component)e.getSource(),e.getX(),e.getY()); }
}
public MyTxt ()
{
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});
ta=new JTextArea(10,30);
add(ta,BorderLayout.CENTER);
Panel p1=new Panel();
add(p1,BorderLayout.SOUTH);
setVisible(true);
setSize(500,500);
//pack();
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();//获取屏幕大小
int w = getSize().width;
int h = getSize().height;
int x = (dim.width-w)/2;
int y = (dim.height-h)/2;
setLocation(x,y);
createmenu();
setJMenuBar(mb);
sp = new JScrollPane(ta);
getContentPane().add(sp);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="打开")
try
{
openfile();
}
catch(IOException ex){}
if(e.getActionCommand()=="保存")
{
try {
savefile();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(e.getActionCommand()=="退出")
{
dispose();
System.exit(0);
}
}
public void savefile() throws IOException
{
FileDialog fd=new FileDialog(this,"保存",FileDialog.SAVE);
fd.setVisible(true);
FileWriter fw=new FileWriter( fd.getDirectory()+fd.getFile());
for(int i=0;i<ta.getText().length();i++)
{
fw.write(ta.getText().charAt(i));
}
fw.close();
}
public void openfile() throws IOException
{
FileDialog fd=new FileDialog(this,"打开",FileDialog.LOAD);
fd.setVisible(true);
FileReader fr=new FileReader( fd.getDirectory()+fd.getFile());
int n=0;
int row=10;
while((n=fr.read())!=-1)
{
ta.append(""+(char)n);
row--;
if(row==0)
{
ta.append("\n");
row=20;
}
}
fr.close();
}
public static void main(String []args)
{
MyTxt tw=new MyTxt();
}
}
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import com.sun.tools.hat.internal.parser.Reader;
public class MyTxt extends JFrame implements ActionListener
{
JTextArea ta;
JMenuItem open,save,myexit,open1,save1;
JMenuItem copy,palse;
JMenuBar mb;
JPopupMenu popm;
JScrollPane sp;
public void createmenu()
{
mb=new JMenuBar();
JMenu m1=new JMenu("文件");
JMenu m2=new JMenu("编辑");
JMenu m3=new JMenu("字体");
mb.add(m1);mb.add(m2);m2.add(m3);
open=new JMenuItem("打开");
//ImageIcon ii = new ImageIcon("a.gif");
//open.setIcon(new ImageIcon("b.gif"));
open.addActionListener(this);
save=new JMenuItem("保存");
save.addActionListener(this);
myexit=new JMenuItem("退出");
myexit.addActionListener(this);
m1.add(open);m1.add(save);m1.add(myexit);
copy=new JMenuItem("复制");
palse=new JMenuItem("粘贴");
m2.add(copy);m2.add(palse);
popm=new JPopupMenu ();
open1=new JMenuItem("打开");
open1.addActionListener(this);
save1=new JMenuItem("保存");
save1.addActionListener(this);
popm.add(open1);popm.add(save1);
ta.add(popm);
ta.addMouseListener(new MyMouseEvent(this));
}
class MyMouseEvent extends MouseAdapter
{
MyTxt myparentFrame;
MyMouseEvent ( MyTxt m)
{
myparentFrame=m;
}
public void mouseReleased(MouseEvent e)
{
if(e.isPopupTrigger())
myparentFrame.popm.show((Component)e.getSource(),e.getX(),e.getY()); }
}
public MyTxt ()
{
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});
ta=new JTextArea(10,30);
add(ta,BorderLayout.CENTER);
Panel p1=new Panel();
add(p1,BorderLayout.SOUTH);
setVisible(true);
setSize(500,500);
//pack();
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();//获取屏幕大小
int w = getSize().width;
int h = getSize().height;
int x = (dim.width-w)/2;
int y = (dim.height-h)/2;
setLocation(x,y);
createmenu();
setJMenuBar(mb);
sp = new JScrollPane(ta);
getContentPane().add(sp);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="打开")
try
{
openfile();
}
catch(IOException ex){}
if(e.getActionCommand()=="保存")
{
try {
savefile();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(e.getActionCommand()=="退出")
{
dispose();
System.exit(0);
}
}
public void savefile() throws IOException
{
FileDialog fd=new FileDialog(this,"保存",FileDialog.SAVE);
fd.setVisible(true);
FileWriter fw=new FileWriter( fd.getDirectory()+fd.getFile());
for(int i=0;i<ta.getText().length();i++)
{
fw.write(ta.getText().charAt(i));
}
fw.close();
}
public void openfile() throws IOException
{
FileDialog fd=new FileDialog(this,"打开",FileDialog.LOAD);
fd.setVisible(true);
FileReader fr=new FileReader( fd.getDirectory()+fd.getFile());
int n=0;
int row=10;
while((n=fr.read())!=-1)
{
ta.append(""+(char)n);
row--;
if(row==0)
{
ta.append("\n");
row=20;
}
}
fr.close();
}
public static void main(String []args)
{
MyTxt tw=new MyTxt();
}
}
2013-09-10
展开全部
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class f1 extends Frame implements ActionListener
{
private MenuBar menubar=new MenuBar();
private Menu filemenu=new Menu("文件");
private Menu editmenu=new Menu("编辑");
private Menu formmenu=new Menu("格式");
private MenuItem[] itemf=new MenuItem[4];
private MenuItem[] iteme=new MenuItem[6];
private MenuItem[] items=new MenuItem[2];
private TextArea tf=new TextArea();
public int a=0,b=0,c=0,style=Font.PLAIN,size=15;
public String s1="red:"+a+" "+"green:"+b+" "+"blue"+c,
s2="宋体";
public String[] sz1={"10","16","24","30","32","36"},
sz2={"宋体","黑体","幼圆","隶书","行楷","Arial","Georgia"},
sz3={"粗体","倾斜","常规","粗斜"};
JDialog dialog=new JDialog(this,"字体",true);
Container cp=dialog.getContentPane();
JLabel[] lb=new JLabel[8];
JLabel lb1=new JLabel(s1,JLabel.LEFT);
JButton b1=new JButton("确定"),
b2=new JButton("取消");
JComboBox jc1=new JComboBox(),
jc2=new JComboBox(),
jc3=new JComboBox();
JScrollBar jb1=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);
JScrollBar jb2=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);
JScrollBar jb3=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class f1 extends Frame implements ActionListener
{
private MenuBar menubar=new MenuBar();
private Menu filemenu=new Menu("文件");
private Menu editmenu=new Menu("编辑");
private Menu formmenu=new Menu("格式");
private MenuItem[] itemf=new MenuItem[4];
private MenuItem[] iteme=new MenuItem[6];
private MenuItem[] items=new MenuItem[2];
private TextArea tf=new TextArea();
public int a=0,b=0,c=0,style=Font.PLAIN,size=15;
public String s1="red:"+a+" "+"green:"+b+" "+"blue"+c,
s2="宋体";
public String[] sz1={"10","16","24","30","32","36"},
sz2={"宋体","黑体","幼圆","隶书","行楷","Arial","Georgia"},
sz3={"粗体","倾斜","常规","粗斜"};
JDialog dialog=new JDialog(this,"字体",true);
Container cp=dialog.getContentPane();
JLabel[] lb=new JLabel[8];
JLabel lb1=new JLabel(s1,JLabel.LEFT);
JButton b1=new JButton("确定"),
b2=new JButton("取消");
JComboBox jc1=new JComboBox(),
jc2=new JComboBox(),
jc3=new JComboBox();
JScrollBar jb1=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);
JScrollBar jb2=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);
JScrollBar jb3=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询