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

📄 example.java

📁 它既有文本编辑器的功能又有浏览器的功能.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 //-------------------剪切------------------------------

    class cutListener implements ActionListener 
    {
        public void actionPerformed(ActionEvent e) 
        {
        	if(e.getSource()==cut||e.getSource()==jbutton6||e.getSource()==itemcut)
              ta.cut();
        }
    }
//------------------新建------------------------------
    
    class NewListener implements ActionListener 
    {
        public void actionPerformed(ActionEvent e) 
        {
        	if(e.getSource()==New||e.getSource()==jbutton1)
              ta.setText(null);
        }
    }
//-----------------粘贴-----------------------------


    class pasteListener implements ActionListener 
    {
        public void actionPerformed(ActionEvent e) 
        {
        	if(e.getSource()==paste||e.getSource()==jbutton5||e.getSource()==itempaste)
              ta.paste();
        }
    }
//---------------日期---------------------------
    
    class dateListener implements ActionListener
   {
  		public void actionPerformed(ActionEvent e)
      {
   			Date d=new Date();
   			ta.setText(d.toString());			
      }
   }
//--------------复制------------------------

    class copyListener implements ActionListener 
    {
        public void actionPerformed(ActionEvent e) 
        {
        	if(e.getSource()==copy||e.getSource()==jbutton4||e.getSource()==itemcopy)
        	
        	ta.copy();
            
        }
    }
//-------------退出---------------------------

    class exitListener implements ActionListener 
    {
        public void actionPerformed(ActionEvent e) 
        {
           int s = JOptionPane.showConfirmDialog(ta,"您确定要退出吗?","景莉莉提醒您",JOptionPane.YES_NO_CANCEL_OPTION);
		   if(s == JOptionPane.YES_OPTION)
		 	System.exit(0);
        }
    }
    
//-------------Myshow窗体----------------------  
    
    public void initAboutDialog()
	{ 
		
		about.getContentPane().add(new Label("My name is JingLili.I come from computer software 062."));  
		
		about.setSize(300,300);
   	    
		
	} 
//--------------------------------保存函数--------------------------------------
	public void save()
	{
		
		int n=fileChooser.showSaveDialog(c);
			if (n==JFileChooser.APPROVE_OPTION)
		   {   		     		    
	          	File file=fileChooser.getSelectedFile();
               try
               {                    	    
                      FileWriter out = new FileWriter(file); 
                      BufferedWriter writer=new  BufferedWriter(out);                                        
                      writer.write(ta.getText());                           
                      writer.close();
                }
                catch (IOException e1)
                    {
                        System.out.println(e1.toString());
                    }
	        }	
	}
	
//-------------------------事件---------------------------------------------------
    class ListenActionForJfilechooser implements ActionListener 
    {
        int result;

        File file;
        
        public void actionPerformed(ActionEvent e)   
        {
            
            if (e.getSource() == open||e.getSource() ==jbutton2)    //打开
            {
                int state = chooser.showOpenDialog(null);
                file = chooser.getSelectedFile();
                if (file != null && state == JFileChooser.APPROVE_OPTION) 
                {
                    try 
                    {
                        filestream = new FileInputStream(file);
                        la.setText("打开的文件是:" + file.getName());
                    } 
                    catch (Exception e1) 
                    {
                        
                        e1.printStackTrace();
                    }
                    try 
                    {

                        ta.read(filestream, this);
                    } 
                    catch (Exception e1) 
                    {

                        e1.printStackTrace();
                    }
                }
            }
            if (e.getSource() == save||e.getSource() ==jbutton3)    //另存为
            {
                result = chooser.showSaveDialog(ta);
                file = null;
                if (result == JFileChooser.APPROVE_OPTION) 
                {
                    file = chooser.getSelectedFile();
                    la.setText("存储文件名为:" + file.getName());
                } 
                else if (result == JFileChooser.CANCEL_OPTION) 
                {
                    la.setText("您没有选择任何文件");
                }

                FileOutputStream fileOutStream = null;

                if (file != null) 
                {
                    try 
                    {
                        fileOutStream = new FileOutputStream(file);
                    } 
                    catch (FileNotFoundException fe) 
                    {
                        la.setText("File Not Found");
                        return;
                    }

                    String content = ta.getText();

                    try 
                    {
                        fileOutStream.write(content.getBytes());
                    } 
                    catch (IOException ioe) 
                    {
                        la.setText("写入文件错误");
                    } 
                    finally 
                    {
                        try 
                        {
                            if (fileOutStream != null)
                                fileOutStream.close();
                        } 
                        catch (IOException ioe2) 
                        {
                        }
                    }
                }
            }
                if(e.getSource()==print||e.getSource()==jbutton7)      //打印
		     {
				printerJob=PrinterJob.getPrinterJob();
				PageFormat pageFormat=printerJob.pageDialog(printerJob.defaultPage());
			    try
			  {
			     boolean boo=printerJob.printDialog();
			     if(boo==true)
				 {
				
					printerJob.print();
			 	 }
			  }
			  catch(PrinterException ee)
			  {
				System.out.println(ee);
			  }
		    }
		    
		     if(e.getSource()==fontcolor)    //字体颜色
		    {
		   	   foregroundColor();
			 
		    }
		    
		    if(e.getSource()==backgroundcolor)  //背景颜色
		    {
		   	  backgroundColor();
			 
		    }
		    if(e.getSource()==show)          //Myshow
		   {
			  initAboutDialog();	
			  about.show();
		   }
		   

         }
     }
        void getThePage(String site)
	{
		try
		{
			content.setPage(site);
		}
		catch(IOException ex)
		{
			JOptionPane.showMessageDialog(this,"连接错误","错误提示",JOptionPane.ERROR_MESSAGE);
		}
    }
    class MyFieldDealing implements ActionListener
    {
    	public void actionPerformed(ActionEvent e)
    	{
    		String str=tf.getText();
    		getThePage(str);
    	}
    }
    
    class MyHyperListener implements HyperlinkListener
    {
    	public void hyperlinkUpdate(HyperlinkEvent e)
    	{
    		if(e.getEventType()==HyperlinkEvent.EventType.ACTIVATED)
    		{
    			String str=e.getURL().toString();
    			getThePage(str);
    		}
    	}
    }
    
//--------------------About窗体----------------------------------------
    class showversion implements ActionListener     
    {

        public void actionPerformed(ActionEvent e) 
        {
            exitversion.setVisible(true);
        }
    }

    class myversion extends Frame 
    {

        Label l1 = new Label("Author :  JingLili ");

        Label l2 = new Label("2007.12.28");

        Label l3 = new Label("Tel:62033285");
        
     

        myversion() 
        {
            this.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 20));

            this.add(l1);
            this.add(l2);
            this.add(l3);
            
            this.setBounds(200, 180, 300,200);

            this.addWindowListener(new myWindowListener1());

        }
    }
     class myWindowListener1 extends WindowAdapter 
    {
        public void windowClosing(WindowEvent e) 
        {
            exitversion.setVisible(false);
        }
    }
    
//------------------About study java 窗体---------------------------------
    class showver implements ActionListener 
    {

        public void actionPerformed(ActionEvent e) 
        {
            exitve.setVisible(true);
        }
    }
    class study extends Frame 
    {

        Label l5 = new Label("With the development of our country ,the language of Java have been becomed more and more importment for us.");

        Label l6 = new Label("So we must  be good at it.");
        
        Label l7 = new Label("Therefore,we must study it very well.");
        study() 
        {
            this.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 20));

            this.add(l5);
            
            this.add(l6);
            
            this.add(l7);
            
            this.setBounds(200, 180, 300, 200);

            this.addWindowListener(new myWindowListener2());

        }
    }

    class myWindowListener2 extends WindowAdapter 
    {
        public void windowClosing(WindowEvent e) 
        {
            exitve.setVisible(false);
        }
    }
    
//-------------------打印函数------------------------------------------------
    public int print(Graphics graphics,PageFormat pageFormat,int pageIndex)
		{
			if(pageIndex==0)
			{
				graphics.translate(80,80);
				print.paintAll(graphics);
				return Printable.PAGE_EXISTS;	
			}
			else if(pageIndex==1)
			{
				graphics.translate(80,80);
				this.paintAll(graphics);
				return Printable.PAGE_EXISTS;			
			}
			else
			{
				return Printable.NO_SUCH_PAGE;
			}
		}
	  		
//------------------字体颜色函数----------------------------------------------	
		public void foregroundColor()
	  {
	   	Color newColor=JColorChooser.showDialog(this,"调色板",ta.getForeground());
		ta.setForeground(newColor);	
	  }	
//------------------背景颜色函数----------------------------------------------
	  public void backgroundColor()
     {
		Color newColor=JColorChooser.showDialog(this,"调色板",ta.getForeground());
		ta.setBackground(newColor);
     }
     
//-----------------主函数------------------------------------------------------     
     public static void main(String args[])
	{
	   Frame1 frame1=new Frame1("简单的文本编辑器和web浏览器");
	   frame1.setBounds(200,100,750, 600);
       frame1.setVisible(true);
	}
    
}


 

⌨️ 快捷键说明

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