分类: 电脑/网络 >> 程序设计 >> 其他编程语言
问题描述:
我们修的汇编语言是JAVA,怎奈自己学术不精现在此象高手请教小程序是期末做课程设计用的题目有日历记事本,学籍管理系统,计算器,画图程序其他的也可以现需要两个程序,谢谢大家!
解析:
import javaio;
import javautilCalendar;
import javaawt;
import javaawtevent;
import javaxswing;
public class NoteBook extends JFrame implements ActionListener,ItemListener,WindowListener,MouseListener{
Container c = thisgetContentPane();
JMenuBar jmb = new JMenuBar();
JColorChooser jcc = new JColorChooser();
JMenu jm1 = new JMenu("文件(F)");
JMenu jm2 = new JMenu("编辑(E)");
JMenu jm3 = new JMenu("格式(O)");
JMenu jm4 = new JMenu("查看(V)");
JMenu jm5 = new JMenu("帮助(H)");
JMenuItem jmi1 = new JMenuItem("新建(N)");
JMenuItem jmi2 = new JMenuItem("打开(O)");
JMenuItem jmi3 = new JMenuItem("保存(S)");
JMenuItem jmi4 = new JMenuItem("退出(X)");
JMenuItem jmi5 = new JMenuItem("撤消(U)");
JMenuItem jmi6 = new JMenuItem("复制(C)");
JMenuItem jmi7 = new JMenuItem("粘贴(P)");
JMenuItem jmi8 = new JMenuItem("剪切(T)");
JMenuItem jmi12 = new JMenuItem("日期和时间");
JMenuItem jmi9 = new JMenuItem("字体(E)");
JCheckBoxMenuItem jcbmi = new JCheckBoxMenuItem("自动换行(W)");
JMenuItem jmi10 = new JMenuItem("删除(S)");
JMenuItem jmi11 = new JMenuItem("背景颜色(H)");
JTextArea jta = new JTextArea(15,15);
JScrollPane jsp = new JScrollPane(jta);
PupolMenu pm = new Pupolmenu();
NoteBook(){
thisaddWindowListener(this);
csetLayout(new BorderLayout());
cadd(jmb,BorderLayoutNORTH);
thissetTitle("新建 文本文档");
jmbadd(jm1);
jm1setMnemonic('f');
jm1addActionListener(this);
jmbadd(jm2);
jm2setMnemonic('e');
jmbadd(jm3);
jm3setMnemonic('o');
jmbadd(jm4);
jm4setMnemonic('v');
jmbadd(jm5);
jm5setMnemonic('h');
jm1add(jmi1);
jmi1addActionListener(this);
jmi1setAccelerator(KeyStrokegetKeyStroke('N',EventCTRL_MASK,false));
jm1addSeparator();
jm1add(jmi2);
jmi2setAccelerator(KeyStrokegetKeyStroke('O',EventCTRL_MASK,false));
jmi2addActionListener(this);
jm1addSeparator();
jm1add(jmi3);
jmi3setAccelerator(KeyStrokegetKeyStroke('S',EventCTRL_MASK,false));
jmi3addActionListener(this);
jm1addSeparator();
jm1add(jmi4);
jmi1setMnemonic('n');
jmi2setMnemonic('o');
jmi3setMnemonic('s');
jmi4setMnemonic('x');
jmi4addActionListener(this);
jm2add(jmi5);
jm2addSeparator();
jm2add(jmi6);
jm2addSeparator();
jm2add(jmi7);
jm2addSeparator();
jm2add(jmi8);
jm2add(jmi12);
jmi12addActionListener(this);
jm3add(jcbmi);
jcbmiaddItemListener(this);
jm3addSeparator();
jm3add(jmi9);
jm4add(jmi10);
jmi10addActionListener(this);
jm5add(jmi11);
jmi11addActionListener(this);
cadd(jsp);
thissetDefaultCloseOperation(JFrameDISPOSE_ON_CLOSE);
thissetSize(500,500);
thissetVisible(true);
}
public void actionPerformed(ActionEvent e){
if(egetSource()==jmi1){
jtasetText("");
thissetTitle("无标题 - 记事本");
}
if(egetSource()==jmi2){
File f1;
JFileChooser jfc1 = new JFileChooser();
int num1 = jfc1showOpenDialog(this);
if(num1==JFileChooserAPPROVE_OPTION){
try{
f1 = jfc1getSelectedFile();
thissetTitle(f1getName());
FileReader fr = new FileReader(f1);
BufferedReader br = new BufferedReader(fr);
String str;
while((str = brreadLine())!=null){
jtasetText(str);
}
frclose();
brclose();
}catch(FileNotFoundException e1){
e1printStackTrace();
}catch(IOException e2){
e2printStackTrace();
}
}
}
if(egetSource()==jmi3){
File f2 = null;
JFileChooser jfc2 = new JFileChooser();
int num2 = jfc2showSaveDialog(this);
if(num2==JFileChooserAPPROVE_OPTION){
f2=jfc2getSelectedFile();
thissetTitle(f2getName());
try{
FileWriter fw = new FileWriter(f2);
BufferedWriter bw = new BufferedWriter(fw);
bwwrite(jtagetText());
bwclose();
fwclose();
}catch(IOException e2){
e2printStackTrace();
}
}
}
if(egetSource()==jmi4){
int a = JOptionPaneshowConfirmDialog(this,"文件已被改变,是否要保存?","提示",JOptionPaneYES_NO_CANCEL_OPTION);
if(a==1){
thisdispose();
}else if(a==0){
File f2 = null;
JFileChooser jfc2 = new JFileChooser();
int num2 = jfc2showSaveDialog(this);
if(num2==JFileChooserAPPROVE_OPTION){
f2=jfc2getSelectedFile();
thissetTitle(f2getName());
try{
FileWriter fw = new FileWriter(f2);
BufferedWriter bw = new BufferedWriter(fw);
bwwrite(jtagetText());
bwclose();
fwclose();
}catch(IOException e2){
e2printStackTrace();
}
thisdispose();
}
}
}
if(egetSource()==jmi12){
Calendar c1 =CalendargetInstance();
int y = c1get(CalendarYEAR);
int m = c1get(CalendarMONTH);
int d = c1get(CalendarDATE);
int h = c1get(CalendarHOUR);
int m1 = c1get(CalendarMINUTE);
int m2 = m+1;
jtasetText(y+"年"+m2+"月"+d+"日"+h+":"+m1);
}
if(egetSource()==jmi11){
Color ccc = JColorChoosershowDialog(this,"color",ColorBLACK);
jtasetSelectedTextColor(ccc);
jtasetBackground(ccc);
}
if(egetSource()==jmi10){
jtareplaceRange("",jtagetSelectionStart(),jtagetSelectionEnd());
}
}
public void itemStateChanged(ItemEvent e2){
if(e2getItemSelectable()==jcbmi){
jtasetLineWrap(true);
}else
jtasetLineWrap(false);
}
public static void main(String[] args){
new NoteBook();
}
public void windowOpened(WindowEvent arg0) {
}
public void windowClosing(WindowEvent arg0) {
int a = JOptionPaneshowConfirmDialog(this,"文件已被改变,是否要保存?","提示",JOptionPaneYES_NO_CANCEL_OPTION);
if(a==1){
thisdispose();
}else if(a==0){
File f2 = null;
JFileChooser jfc2 = new JFileChooser();
int num2 = jfc2showSaveDialog(this);
if(num2==JFileChooserAPPROVE_OPTION){
f2=jfc2getSelectedFile();
thissetTitle(f2getName());
try{
FileWriter fw = new FileWriter(f2);
BufferedWriter bw = new BufferedWriter(fw);
bwwrite(jtagetText());
bwclose();
fwclose();
}catch(IOException e2){
e2printStackTrace();
}
}
if(a==2){
/
}
}
}
public void windowClosed(WindowEvent arg0) {
}
public void windowIconified(WindowEvent arg0) {
TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent arg0) {
TODO Auto-generated method stub
}
public void windowActivated(WindowEvent arg0) {
TODO Auto-generated method stub
}
public void windowDeactivated(WindowEvent arg0) {
TODO Auto-generated method stub
}
public void mouseClicked(MouseEvent arg0) {
TODO Auto-generated method stub
}
public void mousePressed(MouseEvent arg0) {
TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent arg0) {
TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent arg0) {
TODO Auto-generated method stub
}
public void mouseExited(MouseEvent arg0) {
TODO Auto-generated method stub
}
}
package testWrite;
import javaioFile;
import javaioFileInputStream;
import javaioFileOutputStream;
import javaioInputStream;
public class write {
InputStream inStream ;
FileOutputStream fs ;
int bytesum = 0;
int byteread = 0;
String data ;
StringBuffer dd;
public static byte[] readdata(String filePath) {
byte[] data = new byte[2048];// 用于存储读取的文件内容
try {
File file = new File(filePath);
if (fileexists()) {
FileInputStream fis = new FileInputStream(file);
fisread(data);
fisclose();
}else{
Systemoutprintln("文件不存在");
}
} catch ( Exception e) {
}
return data;
}
public void writeFile(String fileCopyPath,byte [] data){
File file = new File(fileCopyPath);
try {
if (!fileexists()) {
filecreateNewFile(); //创建文件
FileOutputStream fos = new FileOutputStream(file);
foswrite(data);
fosclose();
}else{
Systemoutprintln("文件已经存在");
}
} catch (Exception e) {
eprintStackTrace();
}
}
}
package testWrite;
public class writeOne extends write {
public static void main(String[] args) {
//第一种
// writeOne a=new writeOne ();
// byte [] data=areaddata("D:\\Users\\workspace\\testWrite\\src\\testWrite\\writejava");
// awriteFile("D:\\Users\\workspace\\testWrite\\src\\testWrite\\writenewjava",data);
//第二种
writeOne a2=new writeOne ();
Systemoutprintln(SystemgetProperty("userdir"));//userdir指定了当前的路径
String path=SystemgetProperty("userdir");
Systemoutprintln(path);
String writefile="\\src\\testWrite\\writejava";
String writenewfile="\\src\\testWrite\\writenewjava";
String w1=path+writefile; //读取文件的路径
String w2=path+writenewfile; //写入文件路径
byte [] data=a2readdata(w1); //读取文件
a2writeFile(w2 ,data); //写入文件
}
}
本地已经调试通过可以复制writejava 文件 ,注意包,和文件的路径 直接运行第二个java文件就可以了,运行后刷新一下就可以看到复制的文件(备注:我是使用myeclipse环境进行调试)
先到官网下载myeclipse或者eclipse编程软件,并配置java环境变量,在百度搜索栏依次搜索eclipse下载和搜索java环境变量的配置,就可以找到图文并茂的详细教程。下面介绍一下怎么制作小程序:
1、打开myeclispe(eclipse都一样),依次点击File->New->Java Project,然后给这个项目起一个名字(随便起),这里就叫MyFirst然后点击Finish;
2、在myeclipse左侧找到自己建好的MyFirst项目,左键点击,下面有文件件src,点击src,右键,依次点击New->Class,然后给这个新的类起一个名字(随便起),我这里叫MyFirstClass,然后点击Finish;
3、复制粘贴下面这些代码到MyFirstClassjava文件中,然后ctrl+s,保存;
4、在MyFirstClassjava文件的空白处右键选择 Run As -->Java Application,你就会在下方的控制台看到hello worl。
扩展资料:
Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。
参考资料:Java-百度百科
以上就是关于求助:JAVA小程序全部的内容,包括:求助:JAVA小程序、用java语言,编写一个小程序。、java小程序入门等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)