课程设计程序Word格式文档下载.docx

上传人:b****6 文档编号:18951178 上传时间:2023-01-02 格式:DOCX 页数:20 大小:18.12KB
下载 相关 举报
课程设计程序Word格式文档下载.docx_第1页
第1页 / 共20页
课程设计程序Word格式文档下载.docx_第2页
第2页 / 共20页
课程设计程序Word格式文档下载.docx_第3页
第3页 / 共20页
课程设计程序Word格式文档下载.docx_第4页
第4页 / 共20页
课程设计程序Word格式文档下载.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

课程设计程序Word格式文档下载.docx

《课程设计程序Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《课程设计程序Word格式文档下载.docx(20页珍藏版)》请在冰豆网上搜索。

课程设计程序Word格式文档下载.docx

//"

菜单项的四个下拉菜单

//编辑菜单的四个下拉菜单

JMenuItemoptionofmenu[][]=newJMenuItem[][]{{newJMenuItem("

新建"

),newJMenuItem("

打开"

保存"

退出"

)},

{newJMenuItem("

复制"

剪切"

粘贴"

颜色"

{newJMenuItem("

)}

};

voidinitMenu()

{

for(inti=0;

i<

menus.length;

i++)

menu.add(menus[i]);

for(intj=0;

j<

optionofmenu[i].length;

j++)

{

menus[i].add(optionofmenu[i][j]);

optionofmenu[i][j].addActionListener(action);

}

this.setJMenuBar(menu);

}

ActionListeneraction=newActionListener()

{//添加事件监听

publicvoidactionPerformed(ActionEvente)

Stringname=e.getActionCommand();

JMenuItemMI=(JMenuItem)e.getSource();

if("

.equals(name))

content.setText("

"

);

file=null;

elseif("

if(file!

=null)

openfile.setSelectedFile(file);

intreturnVal=openfile.showOpenDialog(mynotepad.this);

if(returnVal==JFileChooser.APPROVE_OPTION)

file=openfile.getSelectedFile();

unfold();

}

elseif("

if(file!

=null)openfile.setSelectedFile(file);

intreturnVal=openfile.showSaveDialog(mynotepad.this);

file=openfile.getSelectedFile();

saving();

elseif("

mynotepadf=newmynotepad();

ints=JOptionPane.showConfirmDialog(f,"

退出?

"

JOptionPane.YES_NO_OPTION);

if(s==JOptionPane.YES_OPTION)

System.exit(0);

content.cut();

{

content.copy();

content.paste();

color=JColorChooser.showDialog(mynotepad.this,"

color);

content.setForeground(color);

about.setSize(300,150);

about.show();

}

};

voidsaving()

try

FileWriterWritef=newFileWriter(file);

Writef.write(content.getText());

Writef.close();

catch(Exceptione)

e.printStackTrace();

voidunfold()

FileReaderReadf=newFileReader(file);

intlen=(int)file.length();

char[]buffer=newchar[len];

Readf.read(buffer,0,len);

Readf.close();

content.setText(newString(buffer));

catch(Exceptione)

e.printStackTrace();

voidinitAboutDialog()

about.setLayout(newGridLayout(3,1));

about.getContentPane().setBackground(Color.white);

about.getContentPane().add(newJLabel("

我的记事本程序"

));

//对话框内容

制作者:

Fwx"

2007年12月"

about.setModal(true);

//设置对话框前端显示

about.setSize(100,100);

about.setLocation(250,170);

//设置对话框显示位置

};

}

publicclassNotepad

publicstaticvoidmain(Stringargs[])

{//入口main函数

mynotepadnoted=newmynotepad();

noted.addWindowListener(newWindowAdapter()

});

noted.setTitle("

//记事本标题

noted.setSize(640,320);

//设置记事本大小

noted.show();

noted.setLocation(150,100);

//设置记事本显示位置

}

2.简单计算器(该java源文件的名称是simplecalculator.java)

classsimplecalculator

staticStringpoint=newString();

staticStringAmal=newString();

staticStringONE=newString();

staticStringTWO=newString();

staticStringTHREE=newString();

staticStringFOUR=newString();

staticStringFIVE=newString();

staticStringSIX=newString();

staticStringSEVEN=newString();

staticStringEIGHT=newString();

staticStringNINE=newString();

staticStringZERO=newString();

staticStringResultState=newString();

staticDoubleQF;

staticJButtonzero=newJButton("

0"

staticJButtonone=newJButton("

1"

staticJButtontwo=newJButton("

2"

staticJButtonthree=newJButton("

3"

staticJButtonfour=newJButton("

4"

staticJButtonfive=newJButton("

5"

staticJButtonsix=newJButton("

6"

staticJButtonseven=newJButton("

7"

staticJButtoneight=newJButton("

8"

staticJButtonnine=newJButton("

9"

staticJButtonadd=newJButton("

+"

staticJButtonsub=newJButton("

-"

staticJButtonmul=newJButton("

*"

staticJButtondiv=newJButton("

/"

staticJButtonQuFan=newJButton("

+/-"

staticJButtonDian=newJButton("

."

staticJButtonequal=newJButton("

="

staticJButtonclear=newJButton("

C"

staticJButtonBaiFen=newJButton("

%"

staticJButtonFenZhiYi=newJButton("

1/x"

staticinti=0;

staticDoubleaddNumber;

staticDoublesubNumber;

staticDoublemulNumber;

staticDoubledivNumber;

staticDoubleequalNumber;

staticDoubletemp;

staticJTextArearesult=newJTextArea(1,20);

publicstaticvoidmain(String[]args)

JFrameframe=newJFrame("

计算器"

result.setEditable(false);

result.setText("

ResultState="

窗口空"

;

JPanelForResult=newJPanel();

JPanelForButton7_clear=newJPanel();

JPanelForButton4_mul=newJPanel();

JPanelForButton1_sub=newJPanel();

JPanelForButton0_equal=newJPanel();

FlowLayoutFLO=newFlowLayout();

ForResult.add(result);

ForButton7_clear.setLayout(FLO);

ForButton7_clear.add(seven);

ForButton7_clear.add(eight);

ForButton7_clear.add(nine);

ForButton7_clear.add(div);

ForButton7_clear.add(clear);

ForButton4_mul.setLayout(FLO);

ForButton4_mul.add(four);

ForButton4_mul.add(five);

ForButton4_mul.add(six);

ForButton4_mul.add(mul);

ForButton4_mul.add(BaiFen);

ForButton1_sub.setLayout(FLO);

ForButton1_sub.add(one);

ForButton1_sub.add(two);

ForButton1_sub.add(three);

ForButton1_sub.add(sub);

ForButton1_sub.add(FenZhiYi);

ForButton0_equal.setLayout(FLO);

ForButton0_equal.add(zero);

ForButton0_equal.add(QuFan);

ForButton0_equal.add(Dian);

ForButton0_equal.add(add);

ForButton0_equal.add(equal);

frame.getContentPane().setLayout(FLO);

frame.getContentPane().add(ForResult);

frame.getContentPane().add(ForButton7_clear);

frame.getContentPane().add(ForButton4_mul);

frame.getContentPane().add(ForButton1_sub);

frame.getContentPane().add(ForButton0_equal);

frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);

frame.setBounds(250,250,245,245);

frame.setResizable(false);

frame.setVisible(true);

clear.addActionListener(newActionListener()

result.setText("

ZERO="

ONE="

TWO="

THREE="

FOUR="

FIVE="

SIX="

SEVEN="

EIGHT="

NINE="

ResultState="

point="

i=0;

zero.addActionListener(newActionListener()

publicvoidactionPerformed(ActionEvente)

ZERO="

已经点击"

ResultState="

窗口不为空"

if(ONE=="

||TWO=="

||THREE=="

||FOUR=="

||FIVE=="

||SIX=="

||SEVEN=="

||EIGHT=="

||NINE=="

{

result.append("

}

if(ResultState=="

result.setText("

});

one.addActionListener(newActionListener()

ONE="

if(point=="

||ZERO!

||ONE=="

&

result.getText()!

two.addActionListener(newActionListener()

TWO="

three.addActionListener(newActionListener()

THREE="

four.addActionListener(newActionListener()

FOUR="

five.addActionListener(newActionListener()

FIVE="

if(ResultS

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 其它模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1