新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
import java.awt.*;
成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都做网站、网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的贡井网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
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类是与存储在剪贴板上的数据的形式有关的类。
}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();
}
});
}//构造函数结束
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){ //构造函数
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); //为菜单项注册动作时间监听器
mb.addActionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
MyMemo.this.dispose();
}
}); //分号不能忘了
} //构造函数完
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);
}
}
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);//文字编辑区域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);//状态栏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的实现对象\n"+"欢迎网友下载研究交流\n\n"+"/","关于JNotePad",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,null,null,null);}});//编辑区键盘事件textArea.addKeyListener(newKeyAdapter(){publicvoidkeyTyped(KeyEvente){processTextArea();}});//编辑区鼠标事件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()){//文件是否为保存状态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("");//设定状态栏stateBar.setText("未修改");//取得系统相依的换行字符StringlineSeparator=System.getProperty("line.separator");//读取文件并附加至文字编辑区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()){//执行另存为saveFileAs();}else{try{//开启指定的文件BufferedWriterbuf=newBufferedWriter(newFileWriter(file));//将文字编辑区的文字写入文件buf.write(textArea.getText());buf.close();//设定状态栏为未修改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代码肯定就是这个了,如下:
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的新手快速入门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
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();
}
}
你自己慢慢的看吧!
1、使用工具--java service wrapper
2、新建一个文件夹,在文件夹目录下再分别创建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启动服务
出现异常错误可以查看logs目录下的log文件
6注意事项:
6.1. 不要改变文件的相对路径
6.2. 安装好服务后,不要移动文件和文件夹
6.3. 也许您该定期清理logs/wrapper.log日志文件,防止日志文件过大
6.4. 备份好数据库和数据文件,定期查看
可以参考