⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mianframe.java

📁 一个简单的文本编辑器,模趽msword写的哈!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    	
        toolbar.addSeparator();
    	String[] editfunctions={"cut","copy","paste"};
    	String[] editpics={"E:\\我的地盘\\我的文件\\java\\java7\\linzhiyang\\Images\\ID_EDIT_CUT.gif",
    			"E:\\我的地盘\\我的文件\\java\\java7\\linzhiyang\\Images\\ID_EDIT_COPY.gif",
    			"E:\\我的地盘\\我的文件\\java\\java7\\linzhiyang\\Images\\ID_EDIT_PASTE.gif"};
    	buildtoolbutton(toolbar,editfunctions,editpics);
    	
    	toolbar.addSeparator();
    	
    	String[] shapefunctions={"Bold","Italic","Underline"};
    	String[] shapepics={"E:\\我的地盘\\我的文件\\java\\java7\\linzhiyang\\Images\\" +
    			"IDC_XML_TABLE_APPEND_ROW.gif","E:\\我的地盘\\我的文件\\java\\" +
    			"java7\\linzhiyang\\Images\\IDC_XML_ALIGN_LEFT.gif","E:\\我的地盘\\" +
    					"我的文件\\java\\java7\\linzhiyang\\Images\\IDC_UPDATE_ELEMENT_CHOICE.gif"};
    	buildtoolbutton(toolbar,shapefunctions,shapepics);
    	
    	toolbar.addSeparator();
    	
    	String[] colorfunctions={"set color"};
    	String[] colorpics={"E:\\我的地盘\\我的文件\\java\\java7\\linzhiyang\\Images\\" +
    			"IDC_REMOVEALLBOOKMARKS.gif"};
    	buildtoolbutton(toolbar,colorfunctions,colorpics);
    	
    	toolbar.addSeparator();
    	
    	JLabel label=new JLabel("insert");
    	toolbar.add(label);
    	
    	toolbar.addSeparator();
    	
    	String[] insertfunctions={"picture","object"};
    	String[] insertpics={"E:\\我的地盘\\我的文件\\java\\java7\\linzhiyang\\Images\\" +
    			"IDC_OPEN_QUESTIONNAIRE_PAGE.gif",
    			"E:\\我的地盘\\我的文件\\java\\java7\\linzhiyang\\Images\\IDC_XML_VALIGN_TOP.gif"};
    	buildtoolbutton(toolbar,insertfunctions,insertpics);
    	
    	toolbar.addSeparator();
    	
    	label=new JLabel("font type");
    	toolbar.add(label);
    	
    	toolbar.addSeparator();
    	
    	String[] combostr1={"Monospaced","Times New Roman","Dialog","宋体","新宋体","楷体"};
    	JComboBox combo=new JComboBox(combostr1);
        combo.setActionCommand("type");
        combo.addActionListener(new ActionSet("type",null));
        toolbar.add(combo);
        
        toolbar.addSeparator();
        
        String[] combostr2={"3","8","14","16","20","26","34","48"};
        combo=new JComboBox(combostr2);
        combo.setActionCommand("size");
        combo.addActionListener(new ActionSet("size",null));
        toolbar.add(combo);
        
        toolbar.addSeparator();
        
        topframe.getContentPane().add(toolbar,BorderLayout.NORTH);   	
   
    }
    
    public void buildtoolbutton(JToolBar toolbar,String[] functions,String[] pics){
    	JButton button;
    	for(int i=0;i<functions.length;i++){
    		ActionSet action=new ActionSet(functions[i],new ImageIcon(pics[i]));
    		button=toolbar.add(action);
    		button.setActionCommand(functions[i]);
    		button.setToolTipText((String)action.getValue(Action.NAME));
    	}
    }   
    
    public JPopupMenu buildpopupmenu(){
    	popupmenu=new JPopupMenu("popup menu");
    	JMenuItem item=popupmenu.add(new ActionSet("cut",new ImageIcon("E:\\我的地盘\\我的文件\\" +
    			"java\\java7\\linzhiyang\\Images\\ID_EDIT_CUT.gif")));
    	item.setActionCommand("cut");
    	item=popupmenu.add(new ActionSet("copy",new ImageIcon("E:\\我的地盘\\我的文件\\" +
    			"java\\java7\\linzhiyang\\Images\\ID_EDIT_COPY.gif")));
    	item.setActionCommand("copy");
    	item=popupmenu.add(new ActionSet("paste",new ImageIcon("E:\\我的地盘\\我的文件\\" +
    			"java\\java7\\linzhiyang\\Images\\ID_EDIT_PASTE.gif")));
    	item.setActionCommand("paste");
    	return popupmenu;
    }
    
    class showpopupmenu extends MouseAdapter{
    	JPopupMenu popupmenu;
    	showpopupmenu(JPopupMenu popupmenu){
    		this.popupmenu=popupmenu;
    	}
    	public void mouseReleased(MouseEvent e){
    		if(e.isPopupTrigger()){
    			popupmenu.show(e.getComponent(),e.getX(),e.getY());
    		}
    	}
    }
    
    UndoManager undo;    
}    
   
  /*  public JMenu buildmenuhelp(){
    	JMenu help=new JMenu("help");
    	JMenuItem about=new JMenuItem("about this program");
    	JMenuItem openhelp=new JMenuItem("open help windows");
    	about.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			showaboutbox();
    		}
    	});
    	openhelp.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			openhelpwindow();
    		}
    	});
    	help.add(about);
    	help.add(openhelp);
    	return help;
    }
    public void showaboutbox(){
    	JOptionPane.showMessageDialog(this, aboutmsg);
    }
    public void openhelpwindow(){
    	JInternalFrame help=new Helpframe();
    	desktop.add(help);
    	try{
    		help.setVisible(true);
    		help.setSelected(true);
    	}catch(Exception e){
    		e.printStackTrace();
    	}
    }
   
    public JMenu buildmenufile(){
    	JMenu file=new JMenu("file");
    	JMenuItem newf=new JMenuItem("new",new ImageIcon(""));
    	JMenuItem open=new JMenuItem("open",new ImageIcon(""));
    	JMenuItem close=new JMenuItem("close",new ImageIcon(""));
    	JMenuItem quit=new JMenuItem("quit",new ImageIcon(""));
    	quit.setEnabled(false);
    	newf.setMnemonic('n');
    	open.setMnemonic('o');
    	close.setMnemonic('c');
    	quit.setMnemonic('q');
    	newf.setAccelerator(KeyStroke.getKeyStroke('l',java.awt.Event.CTRL_MASK,false));
    	open.setAccelerator(KeyStroke.getKeyStroke('m',java.awt.Event.CTRL_MASK,false));
    	close.setAccelerator(KeyStroke.getKeyStroke('n', java.awt.Event.CTRL_MASK,false));
    	quit.setAccelerator(KeyStroke.getKeyStroke('o',java.awt.Event.CTRL_MASK,false));
    	newf.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			makenewframe();
    		}
    	});
    	open.addActionListener(new ActionListener(){
    	public void actionPerformed(ActionEvent e){
    		opendocument();
    	}
    	});
    	close.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			quit();
    		}
    	});
    	
    	file.add(newf);
    	file.add(open);
    	file.addSeparator();
    	file.add(close);
    	file.add(quit);   	
    	return file;
    }
    public JMenu buildmenuedit(){
    	JMenu edit=new JMenu("edit");
    	JMenuItem undo=new JMenuItem("undo");
    	JMenuItem copy=new JMenuItem("copy");
    	JMenuItem cut=new JMenuItem("cut");
    	JMenuItem paste=new JMenuItem("paste");
    	JMenuItem prefs=new JMenuItem("preferences...");
    	edit.add(undo);
    	edit.add(copy);
    	edit.add(cut);
    	edit.add(paste);
    	edit.add(prefs);
    	return edit;
    }
    public JMenu buildmenufont(){
    	JMenu font=new JMenu("font");
    	JCheckBoxMenuItem bold=new JCheckBoxMenuItem("bold");
    	JCheckBoxMenuItem italic=new JCheckBoxMenuItem("italic");
    	JRadioButtonMenuItem al=new JRadioButtonMenuItem("align left");
    	JRadioButtonMenuItem ar=new JRadioButtonMenuItem("align right");
    	JRadioButtonMenuItem ac=new JRadioButtonMenuItem("align center");
    	JRadioButtonMenuItem aj=new JRadioButtonMenuItem("justify");
    	ButtonGroup group=new ButtonGroup();
    	group.add(al);
    	group.add(ac);
    	group.add(ar);
    	group.add(aj);
    	font.add(bold);
    	font.add(italic);
    	font.addSeparator();
    	font.add(al);
    	font.add(ac);
    	font.add(ar);
    	font.add(aj);
    	return font;
    }
    public JMenu buildmenudemo(){
    	JMenu demo=new JMenu("demo");
    	JMenuItem slider=new JMenuItem("slider");
    	JMenuItem tree=new JMenuItem("tree");
    	JMenuItem table=new JMenuItem("table");
    	JMenuItem password=new JMenuItem("password");
    	slider.setMnemonic('s');
    	tree.setMnemonic('t');
    	table.setMnemonic('t');
    	password.setMnemonic('p');
    	slider.setAccelerator(KeyStroke.getKeyStroke('s',java.awt.Event.CTRL_MASK,false));
    	tree.setAccelerator(KeyStroke.getKeyStroke('t',java.awt.Event.CTRL_MASK,false));
    	table.setAccelerator(KeyStroke.getKeyStroke('a',java.awt.Event.CTRL_MASK,false));
    	password.setAccelerator(KeyStroke.getKeyStroke('p',java.awt.Event.CTRL_MASK,false));
    	slider.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			demoslider();
    		}
    	});
    	tree.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			demotree();
    		}
    	});
    	table.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			demotable();
    		}
    	});
    	password.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			demopassword();
    		}
    	});
    	demo.add(slider);
    	demo.add(tree);
    	demo.add(table);
    	demo.add(password);
    	return demo;
    }

    public void demotree(){
    	JInternalFrame jtree=new demotree();
    	desktop.add(jtree);
    	try{
    		jtree.setVisible(true);
    		jtree.setSelected(true);
    	}catch(Exception e){
    		e.printStackTrace();
    	}
    }
    class demotree extends JInternalFrame{
    	public demotree(){
    		super("demo tree structure",true,true,true,true);
    		DefaultMutableTreeNode manager;
    		DefaultMutableTreeNode leader;
    		DefaultMutableTreeNode engineer;
    		DefaultMutableTreeNode top=new DefaultMutableTreeNode("empolyee list");
    		top.add(manager=new DefaultMutableTreeNode("manager"));
    		top.add(leader=new DefaultMutableTreeNode("leader"));
    		top.add(engineer=new DefaultMutableTreeNode("engineer"));
    		manager.add(new DefaultMutableTreeNode("chenbiao"));
    		manager.add(new DefaultMutableTreeNode("chenbin"));
    		manager.add(new DefaultMutableTreeNode("chensan"));
    	    leader.add(new DefaultMutableTreeNode("chenmaozhou"));
    	    leader.add(new DefaultMutableTreeNode("chenhongxue"));
    	    engineer.add(new DefaultMutableTreeNode("chenming"));
    	    engineer.add(new DefaultMutableTreeNode("chenli"));
    	    JTree tree=new JTree(top);
    	    JScrollPane treescroll=new JScrollPane(tree);
    	    treescroll.setBackground(tree.getBackground());
    	    this.getContentPane().add(treescroll);
    	    this.setSize(250,200);
    	    this.setLocation(200,20);
    	}
    }

    public void makenewframe(){
    	JInternalFrame jinew=new Newframe1();
    	//jinew.setLocation(500, 100);//这个也是相对于底板了。
    	desktop.add(jinew);
    	try{
    		jinew.setVisible(true);
    		jinew.setSelected(true);
    	}catch(Exception e){
    		e.printStackTrace();
    	}
    }
    public void opendocument(){
    	JFileChooser chooser=new JFileChooser();
    	chooser.showOpenDialog(this);
    }
	public static void main(String[] args) {
      Mianframe f=new Mianframe();
      f.setVisible(true);
	}
}
   class Newframe1 extends JInternalFrame{
	   static int count=0;
	   static final int offset=10;
	   public Newframe1(){
		   super("",true,true,true,true);//这就是个底板了吧,呵呵!
		   this.setTitle("untitled document"+(count++));
		   JPanel top=new JPanel();
		   top.setBorder(new EmptyBorder(5,10,10,10));
		   top.setLayout(new BorderLayout());
		   JTextArea content=new JTextArea(10,30);//行列。
		   content.setBorder(new EmptyBorder(5,5,5,5));
		   content.setLineWrap(true);
		   JScrollPane textscrollbar=new JScrollPane(content,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		   top.add(textscrollbar,BorderLayout.CENTER);
		   this.getContentPane().add(top);//都是一样的和这句话:this.setcontentpane(top);
		   this.pack();//可能是都有一个底板吧,试试看看!
		   this.setLocation(offset*count, offset*count);//这里就是相对与底板了!
	   }
   }
    class ToolBarAction extends AbstractAction{
    	public ToolBarAction(String name,Icon icon){
    		super(name,icon);
    	}
    	public void actionPerformed(ActionEvent e){
    		
    	}    	
    }*/
/* 	
ToolBarAction tba_new=new ToolBarAction("new",new ImageIcon("E:\\我的地盘\\我的文件\\java 系列\\java7\\linzhiyang\\Images\\ID_FILE_NEW.gif"));
ToolBarAction tba_open=new ToolBarAction("open",new ImageIcon("E:\\我的地盘\\我的文件\\java 系列\\java7\\linzhiyang\\Images\\ID_FILE_OPEN.gif"));
ToolBarAction tba_close=new ToolBarAction("close",new ImageIcon("E:\\我的地盘\\我的文件\\java 系列\\java7\\linzhiyang\\Images\\ID_WSDL_SERVICE_INSERTSERVICE.gif"));
ToolBarAction tba_save=new ToolBarAction("save",new ImageIcon("E:\\我的地盘\\我的文件\\java 系列\\java7\\linzhiyang\\Images\\ID_FILE_SAVE.gif"));
JButton jb;
jb=toolbar.add(tba_new);
jb.setActionCommand("tb_new");
jb.setToolTipText((String)tba_new.getValue(tba_new.NAME));
jb=toolbar.add(tba_open);
jb.setActionCommand("tb_open");
jb.setToolTipText((String)tba_open.getValue(tba_open.NAME));
jb=toolbar.add(tba_close);
jb.setActionCommand("tb_close");
jb.setToolTipText((String)tba_close.getValue(Action.NAME));//都可以的,为什么?
toolbar.addSeparator();
jb=toolbar.add(tba_save);
jb.setActionCommand("tb_save");
jb.setToolTipText((String)tba_save.getValue(Action.NAME));
toolbar.addSeparator();

ToolBarAction tba_b=new ToolBarAction("bold",new ImageIcon(""));
ToolBarAction tba_i=new ToolBarAction("italic",new ImageIcon(""));
ToolBarAction tba_u=new ToolBarAction("underline",new ImageIcon(""));
jb=toolbar.add(tba_b);
jb.setActionCommand("tb_bold");
jb.setToolTipText((String)tba_b.getValue(Action.NAME));
jb=toolbar.add(tba_i);
jb.setActionCommand("tb_italic");
jb.setToolTipText((String)tba_i.getValue(Action.NAME));
jb=toolbar.add(tba_u);
jb.setActionCommand("tb_underline");
jb.setToolTipText((String)tba_u.getValue(Action.NAME));
toolbar.addSeparator();
JLabel jlfont=new JLabel("font type");
toolbar.add(jlfont);
toolbar.addSeparator();
JComboBox jcb=new JComboBox(combostr1);
toolbar.add(jcb);
toolbar.addSeparator();
JLabel jlsize=new JLabel("font size");
toolbar.add(jlsize);
toolbar.addSeparator();
jcb=new JComboBox(combostr2);
toolbar.add(jcb);    	
this.getContentPane().add(toolbar,BorderLayout.NORTH);*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -