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

📄 qinternet.java

📁 java浏览器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			else{
				dangqian=dangqian;
			}
		}
		if (s == button[1]) {
			if(dangqian<vbutton.size()-1)
			try {					
					dangqian=dangqian+1;
					i=dangqian;
					JButton b=vbutton.get(dangqian);
					xianshi(b);
				
					
				} catch (Exception ee) {
				}
				else{
				dangqian=dangqian;
			}
		}
		if (s == button[2]) {
			for(int i=0;i<vbutton.size();i++)
			{
			  vbutton.remove(i);
			  vzujian.remove(i);
			  vbiaoji.remove(i);
			  card.removeLayoutComponent(panel);
			  dangqian = 0;
			  i=dangqian;
			  address.setText("BLANK");	
			  panel.removeAll();
			  panel1.removeAll();
			  panel.setVisible(false);
			  panel.setVisible(true);
			}
	
		}
		if (s == button[3]) {
			if(!issave()){
			try {
				URL url;
				url = new URL(address.getText());
				update(url.toString(), url);
			} catch (Exception ex) {
			}
		}
		}
	
		if (s == button[4]) {
			// www.baidu.com
			URL url;
			try {
				url = new URL("http://www.baidu.com");
				update(url.toString(), url);

				address.setText(url.toString());
			} catch (Exception es) {

			}
		}

		if (e.getActionCommand().equals("panel1")) {
			JButton button = (JButton) s;
			xianshi(button);
			bianse();
			issave();
		}

		if (s.getClass().getName().equals("javax.swing.JMenuItem")) {
			JMenuItem item = (JMenuItem) s;
			if(item.getText().equals("新建")){
				FileDialog f = new FileDialog(frame, "新建文件", FileDialog.LOAD);

				f.setVisible(true);

				path = f.getDirectory() + f.getFile();
				update1(f.getFile(), path);
				
			}
			if (item.getText().equals("打开")) {
				FileDialog f = new FileDialog(frame, "打开文件", FileDialog.LOAD);

				f.setVisible(true);

				path = f.getDirectory() + f.getFile();
				update1(f.getFile(), path);
			}
			if (item.getText().equals("保存")) {
				if (issave()) {
					save();
				}
			}
			if (item.getText().equals("另存为")) {
				FileDialog f = new FileDialog(frame, "保存文件", FileDialog.SAVE);
				f.setVisible(true);
				path = f.getDirectory() + f.getFile();
				save();
			}
			if (item.getText().equals("退出")) {
				System.exit(0);
			}
			if (item.getText().equals("复制")) {
				copy();
			}
			if (item.getText().equals("粘贴")) {
				paste();
			}
			if (item.getText().equals("剪切")) {
				cut();
			}
			if (item.getText().equals("全选")) {
				selectall();
			}
			if (item.getText().equals("在线帮助")) {
			   URL url;
			    try {
				      url = new URL("http://cn.msn.com/");
				      update(url.toString(), url);
                      
				      address.setText(url.toString());
			     } catch (Exception es) {

			}
		}
			if (item.getText().equals("查找")) {
				if (issave()) {
					dia.setVisible(true);
				} else {
					JOptionPane.showMessageDialog(null, "当前页不能查看");
				}
			}
			
			if (item.getText().equals("收藏添加")){
				if(address.getText().equals(""))
				{
					JOptionPane.showMessageDialog(null,"地址栏为空,无法收藏","WARNING",JOptionPane.ERROR_MESSAGE);
				}
				else{
				  try{
				      sc=JOptionPane.showInputDialog(address.getText()+"另存为:");
				      if(sc.equals("")){
					      JOptionPane.showMessageDialog(null,"无法收藏,收藏名为空","WARNING",JOptionPane.ERROR_MESSAGE);
				          }
				
				     else
				     {
				        b.create(sc,address.getText());
				
				        a.shoucang(sc);
				
				      }
			        }
			         catch (Exception es){
                     }
				
		} 
       
			}
			
		}

	}

	public void hyperlinkUpdate(HyperlinkEvent e) {
		if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {

			try {

				URL url = e.getURL();
				update(url.toString(), url);
				address.setText(url.toString());
			} catch (Throwable t) {
				t.printStackTrace();
			}
		}
	}

	public void xianshi(JButton button) {// 确认选择哪个按纽
	
		try {
					URL url;
					i=dangqian;
					dangqian = vbutton.indexOf(button);
					String str=vbiaoji.get(dangqian);
					address.setText(str);
					if(tag==true)
					{
					  url = new URL(address.getText());
					  update(str, url);
					 }
					 
					
					else if(tag==false){				
					update1(button.getText(),str);
					}
					
				} catch (Exception ee) {
				}
		
		
	}

	public void bianse() {// 显示当前显示的页
		for (int f = 0; f < dangqian; f++) {
			JButton button = (JButton) vbutton.get(f);
			button.setBackground(Color.magenta);
		}
		for (int u= dangqian + 1; u < vbutton.size(); u++) {
			JButton button = (JButton) vbutton.get(u);
			button.setBackground(Color.magenta);
		}
		JButton button = (JButton) vbutton.get(dangqian);
		button.setBackground(Color.green);
	}

	public boolean issave() {// 是否能被编辑
		if (vzujian.size() > 0&&!path.equals("path")) {
			if (vzujian.get(dangqian).getClass().getName().equals(
					"javax.swing.JTextArea")) {
				textarea = (JTextArea) vzujian.get(dangqian);
				return true;

			} else
				return false;
		}
		else
			return false;

	}

	public void copy() {
		if (issave()) {
			textarea.copy();
		} else {
			JEditorPane editor = (JEditorPane) vzujian.get(dangqian);
			editor.copy();
		}
	}

	public void cut() {
		if (issave()) {
			textarea.cut();
		}
	}

	public void paste() {
		if (issave()) {
			textarea.paste();
		}
	}

	public void selectall() {
		if (issave()) {
			textarea.setSelectionStart(0);
			textarea.setSelectionEnd(textarea.getText().length());
		} else {
			JEditorPane editor = (JEditorPane) vzujian.get(dangqian);
			editor.setSelectionStart(0);
			editor.setSelectionEnd(editor.getText().length());
		}

	}

	public void save() {// 保存文件
		savefile = new File(path);
		try {
			RandomAccessFile random = new RandomAccessFile(savefile, "rw");
			random.setLength(0);

			String text = textarea.getText();
			for (int i = 0; i < text.length(); i++)
				random.write(text.charAt(i));
			random.close();
		} catch (Exception e) {
		}
	}

	public static void selecttext(String s, String s1) {
		int a = s.length();
		int m = s1.indexOf(s, cc);
		if (m == -1) {
			System.out.println("meiyou");
			cc = 0;
			return;

		} else {

			textarea.setSelectionStart(m);
			textarea.setSelectionEnd(m + a);
			cc += m + a - 1;
	     	System.out.println("" + cc);
		}
	}

	public static void main(String args[]) {
		try {
			UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
		} catch (Exception e) {
		}
		Qinternet frame = new Qinternet();
		Mymenu.getframe(frame);
		frame.setVisible(true);
	}

	public void mouseClicked(MouseEvent e) {// 处理双击事件
		if (e.getClickCount() == 2) {
			JButton button = (JButton) e.getSource();
			int m = vbutton.indexOf(button);
			button.setVisible(false);
			vbutton.remove(m);
			vzujian.remove(m);
			vbiaoji.remove(m);
			card.removeLayoutComponent(panel);
			if (m > 0 && m <= vbutton.size()) {
				dangqian = m - 1;
				i=dangqian;
				bianse();
				path = vbiaoji.get(dangqian);
				card.show(panel, path);
				address.setText(path);
			} else {
				if (vbiaoji.size() == 0) {
					dangqian = 0;
					i=dangqian;
					address.setText("");
					panel.removeAll();
					panel.setVisible(false);
					panel.setVisible(true);
				} else {
					dangqian = 0;
					i=dangqian;
					bianse();
					path = vbiaoji.get(dangqian);
					card.show(panel, path);
             		address.setText(path);
				}
			}
		}
	}

	public void mouseEntered(MouseEvent e) {
		// TODO 自动生成方法存根
	}
	public void mouseExited(MouseEvent e) {
	}
	public void mousePressed(MouseEvent e) {
	}
	public void mouseReleased(MouseEvent e) {
	}
}

 class dialog extends JDialog implements ActionListener {

	public dialog(JFrame frame, String title, boolean modal) {
		super(frame, title, modal);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Qinternet.dialogbutton.addActionListener(this);
		Qinternet.selectfild.addActionListener(this);

		Container cp = getContentPane();
		cp.setLayout(new FlowLayout());
		cp.add(Qinternet.selectfild);
		cp.add(Qinternet.dialogbutton);
		pack();

	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == Qinternet.selectfild
				|| e.getSource() == Qinternet.dialogbutton) {
			String s = Qinternet.selectfild.getText().toString();
			String text = Qinternet.textarea.getText();
			if (!s.trim().equals("")) {

				Qinternet.selecttext(s, text);

				System.out.println("" + Qinternet.cc);
			}else{
				JOptionPane.showMessageDialog(null, "无搜索字符");
			}

		}
	}
}

⌨️ 快捷键说明

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