<del id="d4fwx"><form id="d4fwx"></form></del>
      <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

            <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
          • java最簡單程序源代碼,Java程序源碼

            求一個用JAVA寫的簡單的記事本源代碼程序

            import java.awt.*;

            成都創(chuàng)新互聯(lián)公司堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都做網(wǎng)站、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的貢井網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設合作伙伴!

            import java.awt.event.*;

            import java.io.*;

            import java.awt.datatransfer.*;

            class MyMenuBar extends MenuBar{

            public MyMenuBar(Frame parent){

            parent.setMenuBar(this);

            }

            public void addMenus(String [] menus){

            for(int i=0;imenus.length;i++)

            add(new Menu(menus[i]));

            }

            public void addMenuItems(int menuNumber,String[] items){

            for(int i=0;iitems.length;i++){

            if(items[i]!=null)

            getMenu(menuNumber).add(new MenuItem(items[i]));

            else getMenu(menuNumber).addSeparator();

            }

            }

            public void addActionListener(ActionListener al){

            for(int i=0;igetMenuCount();i++)

            for(int j=0;jgetMenu(i).getItemCount();j++)

            getMenu(i).getItem(j).addActionListener(al);

            }

            }

            class MyFile{

            private FileDialog fDlg;

            public MyFile(Frame parent){

            fDlg=new FileDialog(parent,"",FileDialog.LOAD);

            }

            private String getPath(){

            return fDlg.getDirectory()+"\\"+fDlg.getFile();

            }

            public String getData() throws IOException{

            fDlg.setTitle("打開");

            fDlg.setMode(FileDialog.LOAD);

            fDlg.setVisible(true);

            BufferedReader br=new BufferedReader(new FileReader(getPath()));

            StringBuffer sb=new StringBuffer();

            String aline;

            while((aline=br.readLine())!=null)

            sb.append(aline+'\n');

            br.close();

            return sb.toString();

            }

            public void setData(String data) throws IOException{

            fDlg.setTitle("保存");

            fDlg.setMode(FileDialog.SAVE);

            fDlg.setVisible(true);

            BufferedWriter bw=new BufferedWriter(new FileWriter(getPath()));

            bw.write(data);

            bw.close();

            }

            }

            class MyClipboard{

            private Clipboard cb;

            public MyClipboard(){

            cb=Toolkit.getDefaultToolkit().getSystemClipboard();

            }

            public void setData(String data){

            cb.setContents(new StringSelection(data),null);

            }

            public String getData(){

            Transferable content=cb.getContents(null);

            try{

            return (String) content.getTransferData(DataFlavor.stringFlavor);

            //DataFlavor.stringFlavor會將剪貼板中的字符串轉換成Unicode碼形式的String對象。

            //DataFlavor類是與存儲在剪貼板上的數(shù)據(jù)的形式有關的類。

            }catch(Exception ue){}

            return null;

            }

            }

            class MyFindDialog extends Dialog implements ActionListener{

            private Label lFind=new Label("查找字符串");

            private Label lReplace=new Label("替換字符串");

            private TextField tFind=new TextField(10);

            private TextField tReplace=new TextField(10);

            private Button bFind=new Button("查找");

            private Button bReplace=new Button("替換");

            private TextArea ta;

            public MyFindDialog(Frame owner,TextArea ta){

            super(owner,"查找",false);

            this.ta=ta;

            setLayout(null);

            lFind.setBounds(10,30,80,20);

            lReplace.setBounds(10,70,80,20);

            tFind.setBounds(90,30,90,20);

            tReplace.setBounds(90,70,90,20);

            bFind.setBounds(190,30,80,20);

            bReplace.setBounds(190,70,80,20);

            add(lFind);

            add(tFind);

            add(bFind);

            add(lReplace);

            add(tReplace);

            add(bReplace);

            setResizable(false);

            bFind.addActionListener(this);

            bReplace.addActionListener(this);

            addWindowListener(new WindowAdapter(){

            public void windowClosing(WindowEvent e){

            MyFindDialog.this.dispose();

            }

            });

            }//構造函數(shù)結束

            public void showFind(){

            setTitle("查找");

            setSize(280,60);

            setVisible(true);

            }

            public void showReplace(){

            setTitle("查找替換");

            setSize(280,110);

            setVisible(true);

            }

            private void find(){

            String text=ta.getText();

            String str=tFind.getText();

            int end=text.length();

            int len=str.length();

            int start=ta.getSelectionEnd();

            if(start==end) start=0;

            for(;start=end-len;start++){

            if(text.substring(start,start+len).equals(str)){

            ta.setSelectionStart(start);

            ta.setSelectionEnd(start+len);

            return;

            }

            }

            //若找不到待查字符串,則將光標置于末尾

            ta.setSelectionStart(end);

            ta.setSelectionEnd(end);

            }

            public Button getBFind() {

            return bFind;

            }

            private void replace(){

            String str=tReplace.getText();

            if(ta.getSelectedText().equals(tFind.getText()))

            ta.replaceRange(str,ta.getSelectionStart(),ta.getSelectionEnd());

            else find();

            }

            public void actionPerformed(ActionEvent e) {

            if(e.getSource()==bFind)

            find();

            else if(e.getSource()==bReplace)

            replace();

            }

            }

            public class MyMemo extends Frame implements ActionListener{

            private TextArea editor=new TextArea(); //可編輯的TextArea

            private MyFile mf=new MyFile(this);//MyFile對象

            private MyClipboard cb=new MyClipboard();

            private MyFindDialog findDlg=new MyFindDialog(this,editor);

            public MyMemo(String title){ //構造函數(shù)

            super(title);

            MyMenuBar mb=new MyMenuBar(this);

            //添加需要的菜單及菜單項

            mb.addMenus(new String[]{"文件","編輯","查找","幫助"});

            mb.addMenuItems(0,new String[]{"新建","打開","保存",null,"全選"});

            mb.addMenuItems(1,new String[]{"剪貼","復制","粘貼","清除",null,"全選"});

            mb.addMenuItems(2,new String[]{"查找",null,"查找替換"});

            mb.addMenuItems(3,new String[]{"我的記事本信息"});

            add(editor); //為菜單項注冊動作時間監(jiān)聽器

            mb.addActionListener(this);

            addWindowListener(new WindowAdapter(){

            public void windowClosing(WindowEvent e){

            MyMemo.this.dispose();

            }

            }); //分號不能忘了

            } //構造函數(shù)完

            public void actionPerformed(ActionEvent e){

            String selected=e.getActionCommand(); //獲取菜單項標題

            if(selected.equals("新建"))

            editor.setText("");

            else if(selected.equals("打開")){

            try{

            editor.setText(mf.getData());

            }catch(IOException ie){}

            }

            else if(selected.equals("保存")){

            try{

            mf.setData(editor.getText());

            }catch(IOException ie){}

            }

            else if(selected.equals("退出")){

            dispose();

            }

            else if(selected.equals("剪貼")){

            //將選中的字符串復制到剪貼板中并清除字符串

            cb.setData(editor.getSelectedText());

            editor.replaceRange("",editor.getSelectionStart(),editor.getSelectionEnd());

            }

            else if(selected.equals("復制")){

            cb.setData(editor.getSelectedText());

            }

            else if(selected.equals("粘貼")){

            String str=cb.getData();

            editor.replaceRange(str,editor.getSelectionStart(),editor.getSelectionEnd());

            //粘貼在光標位置

            }

            else if(selected.equals("清除")){

            editor.replaceRange("",editor.getSelectionStart(),editor.getSelectionEnd());

            }

            else if(selected.equals("全選")){

            editor.setSelectionStart(0);

            editor.setSelectionEnd(editor.getText().length());

            }

            else if(selected.equals("查找")){

            findDlg.showFind();

            }

            else if(selected.equals("查找替換")){

            findDlg.showReplace();

            }

            }

            public static void main(String[] args){

            MyMemo memo=new MyMemo("記事本");

            memo.setSize(650,450);

            memo.setVisible(true);

            }

            }

            用Java編寫簡易記事本源代碼

            importjava.awt.BorderLayout;importjava.awt.Container;importjava.awt.Font;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.InputEvent;importjava.awt.event.KeyAdapter;importjava.awt.event.KeyEvent;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.File;importjava.io.FileReader;importjava.io.FileWriter;importjava.io.IOException;importjavax.swing.BorderFactory;importjavax.swing.JFileChooser;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JMenu;importjavax.swing.JMenuBar;importjavax.swing.JMenuItem;importjavax.swing.JOptionPane;importjavax.swing.JPopupMenu;importjavax.swing.JScrollPane;importjavax.swing.JTextArea;importjavax.swing.KeyStroke;importjavax.swing.ScrollPaneConstants;importjavax.swing.SwingConstants;publicclassJNotePadUIextendsJFrame{privateJMenuItemmenuOpen;privateJMenuItemmenuSave;privateJMenuItemmenuSaveAs;privateJMenuItemmenuClose;privateJMenueditMenu;privateJMenuItemmenuCut;privateJMenuItemmenuCopy;privateJMenuItemmenuPaste;privateJMenuItemmenuAbout;privateJTextAreatextArea;privateJLabelstateBar;privateJFileChooserfileChooser;privateJPopupMenupopUpMenu;publicJNotePadUI(){super("新建文本文件");setUpUIComponent();setUpEventListener();setVisible(true);}privatevoidsetUpUIComponent(){setSize(640,480);//菜單欄JMenuBarmenuBar=newJMenuBar();//設置「文件」菜單JMenufileMenu=newJMenu("文件");menuOpen=newJMenuItem("打開");//快捷鍵設置menuOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));menuSave=newJMenuItem("保存");menuSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));menuSaveAs=newJMenuItem("另存為");menuClose=newJMenuItem("關閉");menuClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,InputEvent.CTRL_MASK));fileMenu.add(menuOpen);fileMenu.addSeparator();//分隔線fileMenu.add(menuSave);fileMenu.add(menuSaveAs);fileMenu.addSeparator();//分隔線fileMenu.add(menuClose);//設置「編輯」菜單JMenueditMenu=newJMenu("編輯");menuCut=newJMenuItem("剪切");menuCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,InputEvent.CTRL_MASK));menuCopy=newJMenuItem("復制");menuCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));menuPaste=newJMenuItem("粘貼");menuPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK));editMenu.add(menuCut);editMenu.add(menuCopy);editMenu.add(menuPaste);//設置「關于」菜單JMenuaboutMenu=newJMenu("關于");menuAbout=newJMenuItem("關于JNotePad");aboutMenu.add(menuAbout);menuBar.add(fileMenu);menuBar.add(editMenu);menuBar.add(aboutMenu);setJMenuBar(menuBar);//文字編輯區(qū)域textArea=newJTextArea();textArea.setFont(newFont("宋體",Font.PLAIN,16));textArea.setLineWrap(true);JScrollPanepanel=newJScrollPane(textArea,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);ContainercontentPane=getContentPane();contentPane.add(panel,BorderLayout.CENTER);//狀態(tài)欄stateBar=newJLabel("未修改");stateBar.setHorizontalAlignment(SwingConstants.LEFT);stateBar.setBorder(BorderFactory.createEtchedBorder());contentPane.add(stateBar,BorderLayout.SOUTH);popUpMenu=editMenu.getPopupMenu();fileChooser=newJFileChooser();}privatevoidsetUpEventListener(){//按下窗口關閉鈕事件處理addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){closeFile();}});//菜單-打開menuOpen.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){openFile();}});//菜單-保存menuSave.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){saveFile();}});//菜單-另存為menuSaveAs.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){saveFileAs();}});//菜單-關閉文件menuClose.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){closeFile();}});//菜單-剪切menuCut.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){cut();}});//菜單-復制menuCopy.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){copy();}});//菜單-粘貼menuPaste.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){paste();}});//菜單-關于menuAbout.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){//顯示對話框JOptionPane.showOptionDialog(null,"程序名稱:\nJNotePad\n"+"程序設計:\n\n"+"簡介:\n一個簡單的文字編輯器\n"+"可作為驗收Java的實現(xiàn)對象\n"+"歡迎網(wǎng)友下載研究交流\n\n"+"/","關于JNotePad",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,null,null,null);}});//編輯區(qū)鍵盤事件textArea.addKeyListener(newKeyAdapter(){publicvoidkeyTyped(KeyEvente){processTextArea();}});//編輯區(qū)鼠標事件textArea.addMouseListener(newMouseAdapter(){publicvoidmouseReleased(MouseEvente){if(e.getButton()==MouseEvent.BUTTON3)popUpMenu.show(editMenu,e.getX(),e.getY());}publicvoidmouseClicked(MouseEvente){if(e.getButton()==MouseEvent.BUTTON1)popUpMenu.setVisible(false);}});}privatevoidopenFile(){if(isCurrentFileSaved()){//文件是否為保存狀態(tài)open();//打開}else{//顯示對話框intoption=JOptionPane.showConfirmDialog(null,"文件已修改,是否保存?","保存文件?",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE,null);switch(option){//確認文件保存caseJOptionPane.YES_OPTION:saveFile();//保存文件break;//放棄文件保存caseJOptionPane.NO_OPTION:open();break;}}}privatebooleanisCurrentFileSaved(){if(stateBar.getText().equals("未修改")){returnfalse;}else{returntrue;}}privatevoidopen(){//fileChooser是JFileChooser的實例//顯示文件選取的對話框intoption=fileChooser.showDialog(null,null);//使用者按下確認鍵if(option==JFileChooser.APPROVE_OPTION){try{//開啟選取的文件BufferedReaderbuf=newBufferedReader(newFileReader(fileChooser.getSelectedFile()));//設定文件標題setTitle(fileChooser.getSelectedFile().toString());//清除前一次文件textArea.setText("");//設定狀態(tài)欄stateBar.setText("未修改");//取得系統(tǒng)相依的換行字符StringlineSeparator=System.getProperty("line.separator");//讀取文件并附加至文字編輯區(qū)Stringtext;while((text=buf.readLine())!=null){textArea.append(text);textArea.append(lineSeparator);}buf.close();}catch(IOExceptione){JOptionPane.showMessageDialog(null,e.toString(),"開啟文件失敗",JOptionPane.ERROR_MESSAGE);}}}privatevoidsaveFile(){//從標題欄取得文件名稱Filefile=newFile(getTitle());//若指定的文件不存在if(!file.exists()){//執(zhí)行另存為saveFileAs();}else{try{//開啟指定的文件BufferedWriterbuf=newBufferedWriter(newFileWriter(file));//將文字編輯區(qū)的文字寫入文件buf.write(textArea.getText());buf.close();//設定狀態(tài)欄為未修改stateBar.setText("未修改");}catch(IOExceptione){JOptionPane.showMessageDialog(null,e.toString(),"寫入文件失敗",JOptionPane.ERROR_MESSAGE);}}}privatevoidsaveFileAs(){//顯示文件對話框intoption=fileChooser.showSaveDialog(null);//如果確認選取文件if(option==JFileChooser.APPROVE_OPTION){//取得選擇的文件Filefile=fileChooser.getSelectedFile();//在標題欄上設定文件名稱setTitle(file.toString());try{//建立文件file.createNewFile();//進行文件保存saveFile();}catch(IOExceptione){JOptionPane.showMessageDialog(null,e.toString(),"無法建立新文件",JOptionPane.ERROR_MESSAGE);}}}privatevoidcloseFile(){//是否已保存文件if(isCurrentFileSaved()){//釋放窗口資源,而后關閉程序dispose();}else{intoption=JOptionPane.showConfirmDialog(null,"文件已修改,是否保存?","保存文件?",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE,null);switch(option){caseJOptionPane.YES_OPTION:saveFile();break;caseJOptionPane.NO_OPTION:dispose();}}}privatevoidcut(){textArea.cut();stateBar.setText("已修改");popUpMenu.setVisible(false);}privatevoidcopy(){textArea.copy();popUpMenu.setVisible(false);}privatevoidpaste(){textArea.paste();stateBar.setText("已修改");popUpMenu.setVisible(false);}privatevoidprocessTextArea(){stateBar.setText("已修改");}publicstaticvoidmain(String[]args){newJNotePadUI();}}

            給段最簡單的java代碼 讓我新手看一下

            最簡單的java代碼肯定就是這個了,如下:

            public class MyFirstApp

            {

            public static void main(String[] args)

            {

            System.out.print("Hello world");

            }

            }

            “hello world”就是應該是所有學java的新手看的第一個代碼了。如果是零基礎的新手朋友們可以來我們的java實驗班試聽,有免費的試聽課程幫助學習java必備基礎知識,有助教老師為零基礎的人提供個人學習方案,學習完成后有考評團進行專業(yè)測試,幫助測評學員是否適合繼續(xù)學習java,15天內(nèi)免費幫助來報名體驗實驗班的新手快速入門java,更好的學習java!

            一個簡單的Java程序代碼?

            package com.zpp;public class Charge {

            public static void main(String [] args) {

            if(args.length ==0) {

            System.out.println("parameter error!");

            System.out.println("java com.zpp.Charge [int]");

            return;

            }

            int min = Integer.parseInt(args[0]);

            double money = 0.0;

            if (min = 0) {

            money =0.0;

            System.out.println("not money");

            } else if (min = 60) {

            money = 2.0;

            } else {

            money = 2.0 + (min - 60) * 0.01;

            }

            System.out.println("please pay: " + money);

            }

            } 編譯:javac -d . Charge.java運行:java com.zpp.Charge 111

            求編寫一個超級簡單的Java的程序源代碼

            import java.awt.*;

            import java.awt.event.*;

            import javax.swing.*;

            class ConstructFrame extends JFrame

            {

            private static final long serialVersionUID = 1L;

            String value1="",result,value2="";

            int flag=0,fix=0,sum=1;

            Boolean happy;

            JTextField text=new JTextField(30);

            int flagsum=0;

            Container c=getContentPane();

            JButton buttonx;

            ConstructFrame()

            { super("計算器");

            c.setLayout(null);

            c.setBackground(Color.blue);

            this.setSize(400, 400);

            c.add(text);

            text.setHorizontalAlignment(JTextField.RIGHT);

            final JButton buttonx=new JButton("BackSpace");

            c.add(buttonx);

            buttonx.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            int count=0;

            String temp;

            if(flag==0)

            {

            count=value1.length();

            if(count!=1)

            temp=value1.substring(0, count-1);

            else

            temp="0";

            value1=temp;

            }

            else

            {

            count=value2.length();

            if(count!=1)

            temp=value2.substring(0, count-1);

            else

            temp="0";

            value2=temp;

            }

            text.setText(temp);

            }

            });

            final JButton buttony=new JButton("CE");

            c.add(buttony);

            buttony.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            value1="";

            value2="";

            flag=0;

            text.setText("0");

            }

            });

            final JButton button1=new JButton("1");

            c.add(button1);

            button1.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            String temp;

            if(flag==0)

            {

            value1=value1+1;

            temp=value1;

            }

            else

            {

            value2=value2+1;

            temp=value2;

            }

            text.setText(temp);

            }

            });

            final JButton button2=new JButton(" 2 ");

            c.add(button2);

            button2.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            String temp;

            if(flag==0)

            {

            value1=value1+2;

            temp=value1;

            }

            else

            {

            value2=value2+2;

            temp=value2;

            }

            text.setText(temp);

            }

            });

            final JButton button3=new JButton("3");

            c.add(button3);

            button3.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            String temp;

            if(flag==0)

            {

            value1=value1+3;

            temp=value1;

            }

            else

            {

            value2=value2+3;

            temp=value2;

            }

            text.setText(temp);

            }

            });

            final JButton button4=new JButton("4");

            c.add(button4);

            button4.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            String temp;

            if(flag==0)

            {

            value1=value1+4;

            temp=value1;

            }

            else

            {

            value2=value2+4;

            temp=value2;

            }

            text.setText(temp);

            }

            });

            final JButton button5=new JButton("5");

            c.add(button5);

            button5.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            String temp;

            if(flag==0)

            {

            value1=value1+5;

            temp=value1;

            }

            else

            {

            value2=value2+5;

            temp=value2;

            }

            text.setText(temp);

            }

            });

            final JButton button6=new JButton("6");

            c.add(button6);

            button6.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            String temp;

            if(flag==0)

            {

            value1=value1+6;

            temp=value1;

            }

            else

            {

            value2=value2+6;

            temp=value2;

            }

            text.setText(temp);

            }

            });

            final JButton button7=new JButton("7");

            c.add(button7);

            button7.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            String temp;

            if(flag==0)

            {

            value1=value1+7;

            temp=value1;

            }

            else

            {

            value2=value2+7;

            temp=value2;

            }

            text.setText(temp);

            }

            });

            final JButton button8=new JButton("8");

            c.add(button8);

            button8.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            String temp;

            if(flag==0)

            {

            value1=value1+8;

            temp=value1;

            }

            else

            {

            value2=value2+8;

            temp=value2;

            }

            text.setText(temp);

            }

            });

            final JButton button9=new JButton("9");

            c.add(button9);

            button9.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            String temp;

            if(flag==0)

            {

            value1=value1+9;

            temp=value1;

            }

            else

            {

            value2=value2+9;

            temp=value2;

            }

            text.setText(temp);

            }

            });

            final JButton button0=new JButton("0");

            c.add(button0);

            button0.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            String temp;

            if(flag==0)

            {

            value1=value1+0;

            temp=value1;

            }

            else

            {

            value2=value2+0;

            temp=value2;

            }

            text.setText(temp);

            }

            });

            final JButton buttonadd=new JButton(" + ");

            c.add(buttonadd);

            buttonadd.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            flag=1;

            fix=1;

            flagsum=0;

            }

            });

            final JButton buttonsubtract=new JButton(" - ");

            c.add(buttonsubtract);

            buttonsubtract.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            flag=1;

            fix=2;

            flagsum=0;

            }

            });

            final JButton buttoncheng=new JButton(" * ");

            c.add(buttoncheng);

            buttoncheng.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            flag=1;

            fix=3;

            flagsum=0;

            }

            });

            final JButton buttonchu=new JButton(" / ");

            c.add(buttonchu);

            buttonchu.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            flag=1;

            flagsum=0;

            fix=4;

            }

            });

            final JButton buttonequal=new JButton(" = ");

            c.add(buttonequal);

            buttonequal.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            {

            double temp1,temp2;

            double temp=0;

            flagsum=0;

            temp1=Double.parseDouble(value1);

            temp2=Double.parseDouble(value2);

            flag=0;

            switch(fix)

            {

            case 1: temp=temp1+temp2;break;

            case 2: temp=temp1-temp2;break;

            case 3: temp=temp1*temp2;break;

            case 4: temp=temp1/temp2;break;

            }

            result=Double.valueOf(temp).toString();

            value1=result;

            value2="";

            flag=1;

            text.setText(result);

            }

            });

            final JButton buttonpoint=new JButton(".");

            c.add(buttonpoint);

            buttonpoint.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            { if(flagsum==0)

            {

            String temp;

            if(flag==0 )

            {

            value1=value1+".";

            temp=value1;

            }

            else

            {

            value2=value2+".";

            temp=value2;

            }

            flagsum=1;

            text.setText(temp);

            }

            }

            });

            JButton buttonz=new JButton("Start");

            c.add(buttonz);

            buttonz.addMouseListener(new MouseAdapter()

            {

            public void mousePressed(MouseEvent e)

            { if(sum%2==1)

            {

            happy=true;

            text.setText("0.");

            flag=0;

            }

            else

            {

            happy=false;

            value1="";

            value2="";

            text.setText("");

            }

            text.setEnabled(happy);

            button1.setEnabled(happy);

            button2.setEnabled(happy);

            button3.setEnabled(happy);

            button4.setEnabled(happy);

            button5.setEnabled(happy);

            button6.setEnabled(happy);

            button7.setEnabled(happy);

            button8.setEnabled(happy);

            button9.setEnabled(happy);

            button0.setEnabled(happy);

            buttonx.setEnabled(happy);

            buttony.setEnabled(happy);

            buttonadd.setEnabled(happy);

            buttonsubtract.setEnabled(happy);

            buttonpoint.setEnabled(happy);

            buttonequal.setEnabled(happy);

            buttoncheng.setEnabled(happy);

            buttonchu.setEnabled(happy);

            sum++;

            }

            });

            button1.setEnabled(false);

            button2.setEnabled(false);

            button3.setEnabled(false);

            button4.setEnabled(false);

            button5.setEnabled(false);

            button6.setEnabled(false);

            button7.setEnabled(false);

            button8.setEnabled(false);

            button9.setEnabled(false);

            button0.setEnabled(false);

            buttonx.setEnabled(false);

            buttony.setEnabled(false);

            buttonadd.setEnabled(false);

            buttonsubtract.setEnabled(false);

            buttonpoint.setEnabled(false);

            buttonequal.setEnabled(false);

            buttoncheng.setEnabled(false);

            buttonchu.setEnabled(false);

            text.setEnabled(false);

            text.setBounds(20, 20, 200, 40);

            buttonx.setBounds(20, 60,100, 40);

            buttony.setBounds(140, 60,100, 40);

            buttonz.setBounds(260, 60,80, 40);

            button1.setBounds(20, 120,60, 40);

            button2.setBounds(100, 120,60, 40);

            button3.setBounds(180, 120,60, 40);

            buttonadd.setBounds(260, 120,60, 40);

            button4.setBounds(20, 180,60, 40);

            button5.setBounds(100, 180,60, 40);

            button6.setBounds(180, 180,60, 40);

            buttonsubtract.setBounds(260, 180,60, 40);

            button7.setBounds(20, 240,60, 40);

            button8.setBounds(100, 240,60, 40);

            button9.setBounds(180, 240,60, 40);

            buttoncheng.setBounds(260,240,60,40);

            button0.setBounds(20, 300,60, 40);

            buttonpoint.setBounds(100, 300, 60, 40);

            buttonequal.setBounds(180,300,60, 40);

            buttonchu.setBounds(260, 300,60, 40);

            setVisible(true);

            }

            class MYMouseEvent extends MouseAdapter

            {

            public void mousePressed(MouseEvent e)

            {

            value1=e.toString();

            text.setText(value1);

            }

            }

            }

            class Calutator

            {

            public static void main(String[] args)

            {

            new ConstructFrame();

            }

            }

            你自己慢慢的看吧!

            如何運用Java Service Wrapper將java程序包裝成服務?提供最簡單的java程序源代碼

            1、使用工具--java service wrapper

            2、新建一個文件夾,在文件夾目錄下再分別創(chuàng)建lib,bin,conf,logs,classes文件夾

            3、將下載的wrapper的文件夾中的wrapper.jar,wrappertest.jar,wrapper.dll復制到新建的lib文件夾下,

            將InstallApp-NT.bat,PauseApp-NT.bat,ResumeApp-NT.bat,StartApp-NT.bat,StopAppNT.bat,UninstallApp- NT.bat以及wrapper.exe復制到bin目錄下;

            將wrapper.conf復制到conf目錄下;

            將wrapper.log復制到logs目錄下;

            將要安裝成服務的java程序打成jar包(這里我的是TestServer.jar),連同其他需要的jar包一并放到 classes 目錄下。

            4、配置conf目錄下wrapper.conf文件:

            這里僅僅列出需要修改的地方

            4.1 wrapper.java.command=java

            指明jre,如果本機已配置了jre,那么此項不需更改;否則的話,需要將jre復制到wrapper路徑下

            (和bin在 同一級)

            同時修改wrapper.java.command=../jre/bin/java.exe

            4.2將程序運行需要的jar包都列出來wrapper.jar是必需的

            wrapper.java.classpath.1=../lib/wrapper.jar

            wrapper.java.classpath.2=../classes/TestServer.jar

            wrapper.java.classpath.2=../classes/classes12.jar

            4.3指定程序的主類

            wrapper.app.parameter.1=test.TestServer

            4.4控制臺運行時的名稱

            wrapper.console.title=TestServer

            4.5指定服務的名稱

            wrapper.ntservice.name=TestServer

            4.6windows服務的顯示名稱

            wrapper.ntservice.displayname=TestServer

            4.7服務描述

            wrapper.ntservice.description=TestServer

            4.8啟動模式,默認是自啟動AUTO_START or DEMAND_START

            wrapper.ntservice.starttype=AUTO_START

            5、運行InstallApp-NT.bat安裝服務,運行StartApp-NT.bat啟動服務

            出現(xiàn)異常錯誤可以查看logs目錄下的log文件

            6注意事項:

            6.1. 不要改變文件的相對路徑

            6.2. 安裝好服務后,不要移動文件和文件夾

            6.3. 也許您該定期清理logs/wrapper.log日志文件,防止日志文件過大

            6.4. 備份好數(shù)據(jù)庫和數(shù)據(jù)文件,定期查看

            可以參考

            網(wǎng)站名稱:java最簡單程序源代碼,Java程序源碼
            當前地址:http://www.jbt999.com/article24/heegce.html

            成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供微信公眾號、企業(yè)建站、企業(yè)網(wǎng)站制作、App設計、移動網(wǎng)站建設網(wǎng)站排名

            廣告

            聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

            手機網(wǎng)站建設

              <del id="d4fwx"><form id="d4fwx"></form></del>
              <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

                    <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
                  • 青青草原在线 | 亚洲无码短视频 | 天堂成人在线视频 | 日本骚虎网站 | 尹人在线大香蕉 |