当前位置:文档之家› JAVA实验报告实验六JAVA图形用户界面

JAVA实验报告实验六JAVA图形用户界面

buttonNextMonth.setText("下月"); buttonNextMonth.addActionListener(this); pNorth.add(buttonNextMonth); getContentPane().add(pNorth,BorderLayout.NORTH);
getContentPane().add(pCenter,BorderLayout.CENTER); pCenter.setLayout(new GridLayout(7,7)); for (int i = 0; i < 7; i++) {
jButton11ActionPerformed(evt); } });
jButton12.setText("\u00d7"); 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) {
10 个数字按钮(0-9),4 个加减乘除按钮,一个等号按钮,一个清除按钮,要求将计算 公式和结果显示在文本框中。
运行结果:பைடு நூலகம்
加法:
实验报告的内容与格式按任课教师的要求书写。
主要代码:
private void initComponents() {
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();
jButton8ActionPerformed(evt); } });
jButton9.setText("0"); jButton9.addActionListener(new java.awt.event.ActionListener() {
public void
actionPerformed(java.awt.event.ActionEvent evt) { jButton9ActionPerformed(evt);
jButton15ActionPerformed(evt); } });
实验题 2 编写一个程序,有一个窗口,该窗口为 BorderLayout 布局。窗口的中心 添加一个 Panel 容器:pCenter,pCenter 的布局是 7 行 7 列的 GridLayout 布局,pCenter 的中放置 49 个标签,用来显示日历。窗口北面添加一个 Panel 容器 pNorth,其布局是 FlowLayout 布局,pNorth 放置两个按钮:nextMonth 和 previousMonth 按钮,单击 nextMonth,可以显示当前月的下一个月的日历;单击 previousMonth 按钮,可以显示当 前月的上一个月的日历。窗口的南面添加一个 Panel 容器 pSouth,其布局是 FlowLayout 布局,pSouth 中放置一个标签用来显示一些信息。运行结果如图所示。
jButton13ActionPerformed(evt);
} });
jButton14.setText("+"); jButton14.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt); } });
jButton2.setText("1"); jButton2.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) {
信 息 工 程 学 院1
Java 程序设计 实习报告
JAVA 图形用户界面
实验六 Java 图形用户界面
1.实验目的 (1)掌握图形用户界面基本组件。 (2)了解如何使用布局管理器对组件进行管理。 (3)掌握 Java 事件处理机制。
2.实验内容 实验题 1 编写一个模拟计算器的程序,使用面板和网格布局,添加一个文本框,
} });
jButton10.setText("9"); jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt); } });
jButton3.setText("5"); jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
} });
jButton6.setText("8"); jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
图 3.8 运行结果图 [基本要求] 编写完整程序。 运行结果:
主要代码:
private JLabel[] buttonDay = new JLabel[42]; private JButton[] buttonWeek = new JButton[7]; private JLabel labelMonth = new JLabel(); private JButton buttonLastMonth = new JButton(); private JButton buttonNextMonth = new JButton(); private JPanel pCenter=new JPanel(); private JPanel pNorth=new JPanel(); private JPanel pSouth=new JPanel(); private JLabel time=new JLabel(); public Calender() {
jButton6ActionPerformed(evt); } });
jButton7.setText("4"); jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt); } });
jButton5.setText("6"); jButton5.addActionListener(new
java.awt.event.ActionListener() { public void
actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt);
相关主题