历史
虽然,在Dreamweaver的Behaviors可以为我们方便地使用Javascript程序而不用编写代码,但我们自己了解了Javascript的编程方法后,将能更加方便灵活地应用,也使Javascript的代码更简练.本专题通过对一系列典型程序的剖析,使你快速地掌握Javascript的编程技巧,设计出质量上乘的动态网页打下坚实的基础.在此之前,我们先了解一些Javascript 的基本概念.
JavaScript 有什么特点
Java 与 JavaScript 有什么不同
很多人看到 Java 和 JavaScript 都有"Java"四个字,就以为它们是同一样东西,连我自己当初也是这样.其实它们是完完全全不同的两种东西.Java,全称应该是 Java Applet,是嵌在网页中,而又有自己独立的运行窗口的小程序.Java Applet 是预先编译好的,一个 Applet 文件(.class)用 Notepad 打开阅读,根本不能理解.Java Applet 的功能很强大,可以访问 http、ftp等协议,甚至可以在电脑上种病毒(已有先例了).相比之下,JavaScript 的能力就比较小了.JavaScript 是一种"脚本"("Script"),它直接把代码写到 HTML 文档中,浏览器读取它们的时候才进行编译、执行,所以能查看 HTML 源文件就能查看JavaScript 源代码.JavaScript 没有独立的运行窗口,浏览器当前窗口就是它的运行窗口.它们的相同点,我想只有同是以 Java 作编程语言一点了.
开发 JavaScript 该用什么软件
第一段:Javascript在网页的用法
Javascript加入网页有两种方法:
①.、直接加入HTML文档
这是最常用的方法,大部分含有Javascript的网页都采用这种方法,如:
script language="Javascript"
!--
document.writeln("这是Javascript!采用直接插入的方法!");
//-Javascript结束--
/script
在这个例子中,我们可看到一个新的标签: script....../script,而script language="Javascript" 用来告诉浏览器这是用Javascript编写的程序,需要调动相应的解释程序进行解释.
HTML的注释标签!--和--:用来去掉浏览器所不能识别的Javascript源代码的,这对不支持 Javascript 语言的浏览器来说是很有用的.
//-Javascript结束:双斜杠表示 Javascript的注释部分,即从//开始到行尾的字符都被忽略. 至于程序中所用到的document.write()函数则表示将括号中的文字输出到窗口中去, 这在后面将会详细介绍. 另外一点需要注意的是,script....../script的位置并不是固定的,可以包含在head....../head 或body...../body中的任何地方.
script src=url language="Javascript"/script
其中的Url就是程序文件的地址.同样的,这样的语句可以放在HTML文档头部或主体的任何部分. 如果要实现"直接插入方式"中所举例子的效果,可以首先创建一个Javascript源代码文件"Script.js",其内容如下:
在网页中可以这样调用程序:script src="Script.js" language="Javascript"/script .
第二段:Javascript基本概念
今天这一节只作简单介绍,在以后的例子中结程序再作具体解释其作用.
①.、运算符
运算符就是完成操和的一系列符号,它有七类:
赋值运算符、算术运算符、比较运算符、逻辑运算符、条件运算、位操作运算符和字符串运算符.
运算符和操作数的组合称为表达式,通常分为四类:赋值表达式、算术表达式、布尔表达式和字符串表达式.
Javascript程序是由若干语句组成的,语句是编写程序的指令.Javascript提供了完整的基本编程语句,它们是:
赋值语句、switch选择语句、while循环语句、for循环语句、do while循环语句、break循环中止语句和continue循环中断语句.
函数是命名的语句段,这个语句段可以被当作一个整体来引用不着和执行.使用函数要注意以下几点:
①.)函数由关键字function定义;
Javascript的一个重要功能就是基于对象的功能,通过基于对象的程序设计,可以用更直观、模块化和可重复使用的方式进行程序开发.
一组包含数据的属性和对属性中包含数据进行操作的方法,称为对象.比如要设定网页的背景颜色,所针对的对象就是document,所用的属性名是bgcolor,如document.bgcolor="blue",就是表示使背景的颜色为蓝色.
用户与网页交互时产生的操作,称为事件.绝大部分事都由用户的动作所引发,如:用户按鼠标的按钮,就产生onclick事件,若鼠标的指针的链接上移动,就产生onmouseover事件等等.在Javascript中,事件往往与事件处理程序配套使用.
学习Javascript比较快速有效的方法是先熟悉一些基本概念,然后找几个别人设计好的程序认真仔细地分析一遍,再稍作改动,再看看能否达到预期目的,不断地举一反三,既可以加深对一些参数、设计方法的理解,又可以快速地提高自己的水平.另外,再提醒一下:Javascript对大小写是敏感的,特别是一些对象、方法、属性的大小写一定要一致,要养成一种良好的习惯,否则在调试程序时可要累死你了.
您好.我重新地帮你写了代码,完全地符合了你的图片中的界面要求、功能要求.代码如下:(解决了问题,记得给我分哦~^_^呵呵......)
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Rectangle;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import javax.swing.JTextArea;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JButton;
public class Liuyb extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JTextArea jTextArea = null;
private JScrollPane jScrollPane = null;
private JLabel jLabel1 = null;
private JComboBox jComboBox = null;
private JTextField jTextField = null;
private JButton jButton = null;
private JButton jButton1 = null;
/**
* This is the default constructor
*/
public Liuyb() {
super();
initialize();
}
* This method initializes this
*
* @return void
private void initialize() {
this.setContentPane(getJContentPane());
this.setTitle("留言板程序");
this.setVisible(true);
* This method initializes jContentPane
* @return javax.swing.JPanel
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel1 = new JLabel();
jLabel1.setText("你");
jLabel = new JLabel();
jLabel.setHorizontalAlignment(SwingConstants.CENTER);
jLabel.setText("留言板");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabel, null);
jContentPane.add(getJScrollPane(), null);
jContentPane.add(jLabel1, null);
jContentPane.add(getJComboBox(), null);
jContentPane.add(getJTextField(), null);
jContentPane.add(getJButton(), null);
jContentPane.add(getJButton1(), null);
return jContentPane;
* This method initializes jTextArea
* @return javax.swing.JTextArea
private JTextArea getJTextArea() {
if (jTextArea == null) {
jTextArea = new JTextArea();
jTextArea.setText("留言内容:");
jTextArea.setEditable(false);
return jTextArea;
* This method initializes jScrollPane
* @return javax.swing.JScrollPane
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setViewportView(getJTextArea());
return jScrollPane;
* This method initializes jComboBox
* @return javax.swing.JComboBox
private JComboBox getJComboBox() {
if (jComboBox == null) {
jComboBox = new JComboBox();
String[] mycbox={"微笑","大笑","痛苦"};
jComboBox.addItem(mycbox[0]);
jComboBox.addItem(mycbox[1]);
return jComboBox;
* This method initializes jTextField
* @return javax.swing.JTextField
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
return jTextField;
* This method initializes jButton
* @return javax.swing.JButton
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("提交");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jTextArea.setText(jTextArea.getText()◆"\r\n"◆"你"◆jComboBox.getSelectedItem().toString()◆"地说:"◆jTextField.getText());
});
return jButton;
* This method initializes jButton1
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("清屏");
jButton1.addActionListener(new java.awt.event.ActionListener() {
return jButton1;
jTextArea.setCaretPosition(0);
jTextArea.setCaretPosition((int)jTextArea.getText().length());
public static void main(String args[]){
new Liuyb();
在你确定class类存在的情况下,首先确定代码中是否写入了main方法,其次确定是否有System.out.print()来输出结果
如果是class类存在确定存在,但是还是找不到class类,先使用命令CD (例如 cd d: 进入d盘)来进入和class文件相同的文件目录,然后再使用命令行来解析class文件
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
class test implements ActionListener
{
JFrame frame;
JTextArea ta;
JMenuBar mb;
ButtonGroup bg;
int a=0;
char c1;
int i=0;
public static void main(String[] args)
test that=new test();
that.go();
public void go()
frame=new JFrame("计算器");
Container cp= frame.getContentPane();
cp.setLayout(new FlowLayout());
mb=new JMenuBar();
bg=new ButtonGroup();
p1.setBackground(Color.yellow);
cp.setBackground(Color.CYAN);
frame.setJMenuBar(mb);
ta.setEditable(false);
p1.add(ta);
Border etched=BorderFactory.createEtchedBorder();
Border border=BorderFactory.createTitledBorder(etched,"计算类型");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b1.addActionListener(this);
b10.addActionListener(this);
b11.setActionCommand("*");
b11.addActionListener(this);
rb1.setActionCommand("kxx");
rb1.addActionListener(this);
public void actionPerformed(ActionEvent e) //throws Exception
if (e.getActionCommand()=="bzx")
if (e.getActionCommand()=="kxx")
if (e.getActionCommand()=="1")
ta.append("1");
if (e.getActionCommand()=="0")
ta.append("0");
if (e.getActionCommand()=="◆")
s1=ta.getText();
d1 = Double.parseDouble(s1);
ta.setText("");
i=1;
if (e.getActionCommand()=="-")
if (e.getActionCommand()=="*")
if (e.getActionCommand()=="/")
if (e.getActionCommand()=="=")
if(i==1)
ta.setText("ERROR");
else
if (e.getActionCommand()=="C")
/*if (e.getActionCommand()=="Backspace")
//ta.cut(ta.select(a-1,a));
if (e.getActionCommand()=="1/x")
if (e.getActionCommand()==".")
ta.append(".");
if (e.getActionCommand()=="◆/-")
if (e.getActionCommand()=="x^y")
if (e.getActionCommand()=="√x")
if (e.getActionCommand()=="x!")
if (d10)
ta.setText( "error");
else if (d1==0)
ta.setText( "0.0");
else {
for (int k=1;k=d1 ;k◆◆ )
if (e.getActionCommand()=="sin")
//要实现对象间的比较,就必须实现Comparable接口,它里面有个compareTo方法
//Comparable最好使用泛型,这样,无论是速度还是代码量都会减少
@SuppressWarnings("unchecked")
class Student implements ComparableStudent{
private String studentNo; //学号
private String studentName; //姓名
private double englishScore; //英语成绩
private double computerScore; //计算机成绩
private double mathScore; //数学成绩
private double totalScore; //总成绩
//空构造函数
public Student() {}
//构造函数
public Student(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
this.studentNo = studentNo;
this.studentName = studentName;
this.englishScore = englishSocre;
this.computerScore = computerScore;
this.mathScore = mathScore;
//计算总成绩
public double sum() {
this.totalScore = englishScore◆computerScore◆mathScore;
return totalScore;
//计算评测成绩
public double testScore() {
//实现compareTO方法
@Override
public int compareTo(Student student) {
double studentTotal = student.getTotalScore();
return totalScore==studentTotal?0:(totalScorestudentTotal?1:-1);
//重写toString方法
public String toString(){
return "学号:"◆this.getStudentNo()◆" 姓名:"◆this.getStudentName()◆" 英语成绩:"◆this.getEnglishScore()◆" 数学成绩:"◆this.getMathScore()◆" 计算机成绩:"◆this.getComputerScore()◆" 总成绩:"◆this.getTotalScore();
//重写equals方法
public boolean equals(Object obj) {
if(obj == null){
return false;
if(!(obj instanceof Student)){
Student student = (Student)obj;
if(this.studentNo.equals(student.getStudentName())) { //照现实来说,比较是不是同一个学生,应该只是看他的学号是不是相同
return true;
} else {
/*以下为get和set方法,我个人认为,totalScore的set的方法没必要要,因为它是由其它成绩计算出来的
在set方法中,没设置一次值,调用一次sum方法,即重新计算总成绩
public String getStudentNo() {
return studentNo;
public void setStudentNo(String studentNo) {
sum();
public String getStudentName() {
return studentName;
public void setStudentName(String studentName) {
public double getEnglishScore() {
return englishScore;
public void setEnglishScore(double englishScore) {
this.englishScore = englishScore;
public double getComputerScore() {
return computerScore;
public void setComputerScore(double computerScore) {
public double getMathScore() {
return mathScore;
public void setMathScore(double mathScore) {
public double getTotalScore() {
//Student子类学习委员类的实现
class StudentXW extends Student {
//重写父类Student的testScore()方法
public StudentXW() {}
//StudentXW的构造函数
public StudentXW(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
super(studentNo,studentName,englishSocre,computerScore,mathScore);
//Student子类班长类的实现
class StudentBZ extends Student {
public StudentBZ() {}
public StudentBZ(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
//测试类
public class Test {
public static void main(String[] args) {
//生成若干个student类、StudentXW类、StudentBZ类
for(int i = 0 ; istudents.length; i◆◆){
double avgScore = students[i].testScore();
System.out.println(students[i].getStudentName()◆"学生的评测成绩为:"◆ avgScore◆"分");
运行结果为:
先说说回复吧:
假如:
留言表(id , text )两个字段
回复表( id , text parentId )用来存放留言表id 三个字段
目前有一条留言
①.001,'这是一条留言';
那么给这条留言的回复就是
回复后点保存时,将数据传入后台,数据库做insert操作就行了
删除一样的
如果删除回复,直接传入回复的ID 即可
如果删除留言,得先判断该留言有没有回复,如果有回复,则先删除回复,在删除留言(外键约束)
以上就是土嘎嘎小编为大家整理的java写留言源代码简书相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!