java程序设计教案(Java程序设计教程的目录)

:暂无数据 2026-10-07 05:30:02 :0

java程序设计教案(Java程序设计教程的目录)

大家好,java程序设计教案相信很多的网友都不是很明白,包括Java程序设计教程的目录也是一样,不过没有关系,接下来就来为大家分享关于java程序设计教案和Java程序设计教程的目录的一些知识点,大家可以关注收藏,免得下次来找不到哦,下面我们开始吧!

本文目录

Java程序设计教程的目录

第1章 Java基础入门 1
1.1 Java语言概述 1
1.1.1 Java语言的发展及应用前景 1
1.1.2 Java语言的特点 2
1.2 Java程序开发与运行环境 4
1.2.1 Java开发环境及安装 4
1.2.2 开发环境设境 4
1.3 Java的两类应用程序开发过程举例 5
1.3.1 Java Application开发过程举例 5
1.3.2 Java Applet开发过程举例 7
1.4 小 结 8
1.5 习 题 8
第2章 基本数据类型 9
2.1 数据类型综述 9
2.2 变量和常量 10
2.2.1 标识符 10
2.2.2 常量(Constant Variables) 11
2.2.3 变量(Variables) 11
2.3 基本数值数据类型 13

Java程序设计

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.*;
import javax.swing.*;

public class WordProcessSystem extends JFrame{
private JFileChooser chooser;
private JTextArea textArea;
private File file;
private String string = ““;
private Font font;

public WordProcessSystem(){
super();
setTitle(“日记记事本“);
setBounds(100, 100,600, 500);
getContentPane().setLayout(new BorderLayout());
getContentPane().setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu(“文件“);

JMenuItem menuItem = new JMenuItem(“新建“);
menuItem.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
String str1 = JOptionPane.showInputDialog(“请输入新建文件名:“);
try {
file = new File(“E:\\“, str1 + “.txt“);
if(file.exists()){
JOptionPane.showMessageDialog(null, “文件名已存在!“);
}
else{
file.createNewFile();
}
} catch (Exception e1){
}
}
});

chooser = new JFileChooser();
chooser.setCurrentDirectory(new File(“.“));
JMenuItem menuItem1 = new JMenuItem(“打开“);
menuItem1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int result = chooser.showOpenDialog(null);
if(result == JFileChooser.APPROVE_OPTION){
String str = chooser.getSelectedFile().toString();
try {
file = new File(str);
readFromFile(file);
textArea.setText(string);
} catch (Exception e1) {
}
}
}
});
JMenuItem menuItem2 = new JMenuItem(“退出“);
menuItem2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
JMenuItem menuItem3 = new JMenuItem(“保存“);
menuItem3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String string = textArea.getText();
try {
writeToFile(file, string);
} catch (Exception e1) {
}
}
});
menuItem3.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e){
if(e.getKeyChar() == KeyEvent.VK_C){
String string = textArea.getText();
try {
writeToFile(file, string);
} catch (Exception e1) {
}
}
}
});
JMenuItem menuItem4 = new JMenuItem(“另存为“);
menuItem4.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
String s1 = JOptionPane.showInputDialog(“请输入保存文件路径和文件名:“);
file = new File(s1);
System.out.println(file.getPath());
try {
writeToFile(file, string);
System.out.println(“aaaa“);
} catch (Exception e1) {
}
}

});

menu.add(menuItem);
menu.add(menuItem1);
menu.add(menuItem2);
menu.add(menuItem3);
menu.add(menuItem4);

JMenu menu2 = new JMenu(“格式“);
final JMenu menu3 = new JMenu(“字体“);
String fontString = {“宋体“,“楷体“,“隶书“};
final JMenuItem menu3_1 = new JMenuItem[fontString.length];
for(int i = 0;i 《 fontString.length;i++){
String changeString = ““;
menu3_1[i] = new JMenuItem(fontString[i]);
menu3_1[i].setActionCommand(changeString + i);
menu3_1[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand().charAt(0)) {
case ’0’:
font = new Font(“宋体“,Font.PLAIN,20);
textArea.setFont(font);
break;
case ’1’:
font = new Font(“楷体“,Font.PLAIN,18);
textArea.setFont(font);
break;
case ’2’:
font = new Font(“隶书“,Font.BOLD,18);
textArea.setFont(font);
break;
default:
break;
}
}});
menu3.add(menu3_1[i]);
}

JMenu menu4 = new JMenu(“字号“);
String fontBig = {“10“,“15“,“20“,“25“,“30“,“35“,“40“};
final JMenuItem menu4_1 = new JMenuItem[fontBig.length];
for(int i = 0;i 《 fontBig.length;i++){
String changeString = ““;
menu4_1[i] = new JMenuItem(fontBig[i]);
menu4_1[i].setActionCommand(changeString + i);
menu4_1[i].addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand().charAt(0)) {
case ’0’:
font = new Font(menu3.getText(),Font.PLAIN,10);
textArea.setFont(font);
break;
case ’1’:
font = new Font(menu3.getText(),Font.PLAIN,15);
textArea.setFont(font);
break;
case ’2’:
font = new Font(menu3.getText(),Font.PLAIN,20);
textArea.setFont(font);
break;
case ’3’:
font = new Font(menu3.getText(),Font.PLAIN,25);
textArea.setFont(font);
break;
case ’4’:
font = new Font(menu3.getText(),Font.PLAIN,30);
textArea.setFont(font);
break;
case ’5’:
font = new Font(menu3.getText(),Font.PLAIN,35);
textArea.setFont(font);
break;
case ’6’:
font = new Font(menu3.getText(),Font.PLAIN,40);
textArea.setFont(font);
break;
default:
break;
}
}});
menu4.add(menu4_1[i]);
}

menu2.add(menu3);
menu2.add(menu4);

menuBar.add(menu);
menuBar.add(menu2);
setJMenuBar(menuBar);
textArea = new JTextArea();
textArea.setVisible(true);
textArea.setLineWrap(true);
// textArea.setFont(new Font(“宋体“,Font.BOLD,20));
add(textArea);

JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setSize(600, 410);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
add(scrollPane);
}

public void readFromFile(File f) throws IOException{
FileReader fReader = new FileReader(file);
BufferedReader bReader = new BufferedReader(fReader);
char data = new char;
int length = 0;
while((length = fReader.read(data)) 》 0){
string += new String(data,0,length);
}
// string = new String(““);
// while(true){

// String s1 = bReader.readLine();

// if(s1 == null){
// break;
// }
// string += (s1 + “\n“);

bReader.close();
fReader.close();
}

public void writeToFile(File file,String string) throws IOException{
if(!file.exists()){
file.createNewFile();
}
FileWriter fWriter = new FileWriter(file);
fWriter.write(string);
fWriter.close();
}

public static void main(String args) {
WordProcessSystem wordProcessSystem = new WordProcessSystem();
wordProcessSystem.setVisible(true);
}
}
不好意思,这个没有实现查找和替换功能,你自己可以加上去。

java程序设计

成绩我定义成double了,另外平均分我给你保留两位小数:

public class Student {
private String No; //学号
private String name; //姓名
private String gender; //性别
private int age; //年龄
private double chinese; //语文
private double math; //数学
private double english; //英语

//构造函数
public Student(String no,
String name,
String gender,
int age,
double chinese,
double math,
double english) {
No = no;
this.name = name;
this.gender = gender;
this.age = age;
this.chinese = chinese;
this.math = math;
this.english = english;
}

@Override
public String toString() {
return “Student{“ +
“No=’“ + No + ’\’’ +
“, name=’“ + name + ’\’’ +
“, gender=’“ + gender + ’\’’ +
“, age=’“ + age + ’\’’ +
“, chinese=“ + chinese +
“, math=“ + math +
“, english=“ + english +
’}’;
}

//计算总分
public double getSum() {
return this.chinese + this.math + this.english;
}

//计算平均分
public double getAverage() {
return (this.chinese + this.math + this.english) / 3;
}
}

测试类:

class Test {
public static void main(String args) {
Student student = new Student(
“20190001“,
“张三“,
“男“,
18,
109.5,
89.0,
110.0);
double sum = student.getSum();
double average = student.getAverage();
System.out.println(“该学生的信息为:“ + student.toString());
System.out.println(“该学生的总分为:“ + sum);
System.out.println(“该学生的平均分为:“ + String.format(“%.2f“, average));
}
}


运行结果:


这代码会挤在一起,我给你截个图看看:

Student类:

3-28行

28-51行

Test类:

文章分享结束,java程序设计教案和Java程序设计教程的目录的答案你都知道了吗?欢迎再次光临本站哦!

java程序设计教案(Java程序设计教程的目录)

本文编辑:admin

更多文章:


python语言程序设计是什么(python语言是什么)

python语言程序设计是什么(python语言是什么)

各位老铁们好,相信很多人对python语言程序设计是什么都不是特别的了解,因此呢,今天就来为大家分享下关于python语言程序设计是什么以及python语言是什么的问题知识,还望可以帮助大家,解决大家的一些困惑,下面一起来看看吧!

2026年10月15日 12:00

windows程序设计第五版(《WINDOWS程序设计》和《WINDOWS核心编程》的区别)

windows程序设计第五版(《WINDOWS程序设计》和《WINDOWS核心编程》的区别)

本篇文章给大家谈谈windows程序设计第五版,以及《WINDOWS程序设计》和《WINDOWS核心编程》的区别对应的知识点,文章可能有点长,但是希望大家可以阅读完,增长自己的知识,最重要的是希望对各位有所帮助,可以解决了您的问题,不要忘了

2026年10月15日 11:30

issued retroactively(FORM E上盖“ISSUED RETROACTIVELY”的问题,小女在线等待)

issued retroactively(FORM E上盖“ISSUED RETROACTIVELY”的问题,小女在线等待)

各位老铁们,大家好,今天由我来为大家分享issued retroactively,以及FORM E上盖“ISSUED RETROACTIVELY”的问题,小女在线等待的相关问题知识,希望对大家有所帮助。如果可以帮助到大家,还望关注收藏下本站

2026年10月15日 10:30

f发音是什么?printf的返回值是什么

f发音是什么?printf的返回值是什么

大家好,关于f很多朋友都还不太明白,不过没关系,因为今天小编就来为大家分享关于f发音是什么的知识点,相信应该可以解决大家的一些困惑和问题,如果碰巧可以解决您的问题,还望关注下本站哦,希望对各位有所帮助!

2026年10月15日 10:10

begin和start的区别(start与begin的区别)

begin和start的区别(start与begin的区别)

其实begin和start的区别的问题并不复杂,但是又很多的朋友都不太了解start与begin的区别,因此呢,今天小编就来为大家分享begin和start的区别的一些知识,希望可以帮助到大家,下面我们一起来看看这个问题的分析吧!

2026年10月15日 09:20

vant官网中文(范特365 是韩国化妆品VANT36.5吗)

vant官网中文(范特365 是韩国化妆品VANT36.5吗)

大家好,今天小编来为大家解答以下的问题,关于vant官网中文,范特365 是韩国化妆品VANT36.5吗这个很多人还不知道,现在让我们一起来看看吧!

2026年10月15日 09:10

特殊字符是指什么?正则表达式中一些特殊字符的用法

特殊字符是指什么?正则表达式中一些特殊字符的用法

大家好,特殊字符相信很多的网友都不是很明白,包括特殊字符是指什么也是一样,不过没有关系,接下来就来为大家分享关于特殊字符和特殊字符是指什么的一些知识点,大家可以关注收藏,免得下次来找不到哦,下面我们开始吧!

2026年10月15日 08:10

特殊符号网名大全花样符号(特殊符号昵称有哪些)

特殊符号网名大全花样符号(特殊符号昵称有哪些)

本篇文章给大家谈谈特殊符号网名大全花样符号,以及特殊符号昵称有哪些对应的知识点,文章可能有点长,但是希望大家可以阅读完,增长自己的知识,最重要的是希望对各位有所帮助,可以解决了您的问题,不要忘了收藏本站喔。

2026年10月15日 07:30

prison break(越狱(prison break)到底是在讲个什么)

prison break(越狱(prison break)到底是在讲个什么)

各位老铁们好,相信很多人对prison break都不是特别的了解,因此呢,今天就来为大家分享下关于prison break以及越狱(prison break)到底是在讲个什么的问题知识,还望可以帮助大家,解决大家的一些困惑,下面一起来看看

2026年10月15日 06:50

c程序设计第五版教学视频(求C程序设计(第五版)谭浩强教材源代码、视频课件等电子版资料!谢谢大家!)

c程序设计第五版教学视频(求C程序设计(第五版)谭浩强教材源代码、视频课件等电子版资料!谢谢大家!)

各位老铁们,大家好,今天由我来为大家分享c程序设计第五版教学视频,以及求C程序设计(第五版)谭浩强教材源代码、视频课件等电子版资料!谢谢大家!的相关问题知识,希望对大家有所帮助。如果可以帮助到大家,还望关注收藏下本站,您的支持是我们最大的动

2026年10月15日 06:40

最近更新

热门文章

标签列表