?? qinternet.java
字號:
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 + -