.
信 息 工 程 学 院1
Java程序设计 实习报告
JAVA图形用户界面
实验六Java图形用户界面
1.实验目的
(1)掌握图形用户界面基本组件。
(2)了解如何使用布局管理器对组件进行管理。 (3)掌握Java事件处理机制。 2.实验内容
实验题1 编写一个模拟计算器的程序,使用面板和网格布局,添加一个文本框,10个数字按钮(0-9),4个加减乘除按钮,一个等号按钮,一个清除按钮,要求将计算公式和结果显示在文本框中。
运行结果:
实验报告的内容与格式按任课教师的要求书写。 word范文
.
加法:
主要代码:
private void initComponents() {
word范文
jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jButton7 = new javax.swing.JButton(); jButton8 = new javax.swing.JButton(); jButton9 = new javax.swing.JButton(); jButton10 = new javax.swing.JButton(); jButton11 = new javax.swing.JButton(); jButton12 = new javax.swing.JButton(); jButton13 = new javax.swing.JButton(); jButton14 = new javax.swing.JButton(); jButton15 = new javax.swing.JButton(); jTextField1 = new javax.swing.JTextField();
word范文
.
setStub(null);
jButton1.setText(\);
jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt);
}
});
jButton2.setText(\);
jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt);
}
});
jButton3.setText(\);
jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt);
}
});
jButton4.setText(\);
jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt);
}
});
jButton5.setText(\);
jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt);
}
});
word范文
.
jButton6.setText(\);
jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt);
}
});
jButton7.setText(\);
jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt);
}
});
jButton8.setText(\);
jButton8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton8ActionPerformed(evt);
}
});
jButton9.setText(\);
jButton9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton9ActionPerformed(evt);
}
});
jButton10.setText(\);
jButton10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton10ActionPerformed(evt);
}
});
jButton11.setText(\);
jButton11.addActionListener(new java.awt.event.ActionListener() {
.
});
public void actionPerformed(java.awt.event.ActionEvent evt) { }
jButton11ActionPerformed(evt);
jButton12.setText(\);
jButton12.addActionListener(new java.awt.event.ActionListener() { });
public void actionPerformed(java.awt.event.ActionEvent evt) { }
jButton12ActionPerformed(evt);
jButton13.setText(\);
jButton13.addActionListener(new java.awt.event.ActionListener() { });
public void actionPerformed(java.awt.event.ActionEvent evt) { }
jButton13ActionPerformed(evt);
jButton14.setText(\);
jButton14.addActionListener(new java.awt.event.ActionListener() { });
public void actionPerformed(java.awt.event.ActionEvent evt) { }
jButton14ActionPerformed(evt);
jButton15.setText(\);
jButton15.addActionListener(new java.awt.event.ActionListener() { });
public void actionPerformed(java.awt.event.ActionEvent evt) { }
jButton15ActionPerformed(evt);
实验题2 编写一个程序,有一个窗口,该窗口为BorderLayout布局。窗口的中心添加一个Panel容器:pCenter,pCenter的布局是7行7列的GridLayout布局,pCenter的中放置49个标签,用来显示日历。窗口北面添加一个Panel容器pNorth,其布局是
word范文