Student No.: _______________ Name: ________________________________________
1
TK2934 Object-Oriented Programming
Project : GUI & Event
In this lab you will be using the following Java Swing & awt classes:
• container – JFrame, JPanel
• components – JButton, JLabel, JTextField, JRadioButton, JComboBox
• layout managers – FlowLayout, GridLayout, BorderLayout
• component property – Color, Font
• event handling – ActionListener, ItemListener
Stage 1
Purpose: To change the attributes of the components
Stage output: A GUI with nice font and color.
Task Remarks Evaluation/Answer
1. Get a copy of Project.java from your instructor. Make a copy of Project.java and name it as
ProjStage1.java
2. Compile and run the program.
3. Change the font and color of the
labels.
Use methods:
• setFont(new Font(....));
• setForeground(Color);
and class :
• Font(String name, int style, int
size)
Check:
The output should look similar to the figure below.
Figure 1
Time:
Student No.: _______________ Name: ________________________________________
2
Stage 2
Purpose: To add JRadioButtons to the right panel and handle the events.
Stage output: An application with random addition questions.
Task Remarks Evaluation
1. Make a copy of ProjStage1.java
and name it ProjStage2.java
2. Create a panel named rightP
and add 2 radiobuttons ("Add" &
"Subtract")
3. Add the panel to the EAST (or
any other area) of pane.
4. Create a panel named mathP
and add to CENTER of pane
(comment the statement to add
mainP panel).
5. Generate 2 random numbers
between 0 to 9
6. Display the title and the addition
question as in Figure 2. Use nice
and interesting fonts and colors.
Use the following expression:
(int) (Math.random * max) + 1;
where max = 9
Check:
The output should look similar to the figure below.
Figure 2
Time:
Student No.: _______________ Name: ________________________________________
3
7. Handle the event such that when
the user input the correct answer
(and pressed enter), your
program should display
responds as in Figure 3.
Check:
The output should look similar to the figure below.
Figure 3
8. Test with incorrect answers.
Your program should respond
accordingly and request the user
to try again. (Figure 4)
Check:
The output should look similar to the figure below.
Figure 4
Student No.: _______________ Name: ________________________________________
4
Stage 3
Purpose: To handle event for subtraction questions.
Stage output: An application with random addition and subtraction questions.
Task Remarks Evaluation
1. Make a copy of ProjStage2.java
and name it ProjStage3.java
2. Handle the event such that when
the user select "Subtract"
radio button, a randomly
generated subtraction question
will be displayed
3. Handle the event for the
subtraction question. (Figure 5)
4. Test your program by clicking on
the "Add" radio button. Your
program should display a new
random addition question with
the event handling described in
Stage 2.
5. Test your program by clicking on
the "Subtract" radio button.
Your program should display a
new random subtraction
question with the event handling
subscribe in task (2) above.
Important:
Your subtraction question should
always have a positive answer.
Stage 4
Purpose: To handle panel switching.
Stage output: An application that can switch between two panels.
Task Remarks Evaluation
1. Make a copy of ProjStage3.java
and name it ProjStage4.java
2. Add a new radio button labeled
"Word Game" to the right panel.
3. Create a panel named wordP.
Time:
Time:
Student No.: _______________ Name: ________________________________________
5
4. Add a label "GUESS THE WORD"
to the panel
5. Handle the event such that :
a) when the user clicked "Word
Game", wordP panel will be
displayed at the CENTER of
pane
b) when the user clicked "Add",
mathP panel with random
addition question will be
displayed.
c) when the user clicked
"Subtract", mathP panel
with random subtraction
question will be displayed.
6. Test your program
Use the following statements to
switch panels:
pane.remove(currentP);
pane.add(wordP);
pane.revalidate();
currentP = wordP;
pane.repaint();
where currentP is initialized to
panel mathP.
7. Update your program such that
when the program started, the
mainP panel is displayed.
Hint:
initialize currentP to mainP
and add mainP to CENTER.
Stage 5
Purpose: To create an interface for guess a word game
Stage output: A GUI for the word game.
Task Remarks Evaluation
1. Make a copy of ProjStage4.java
and name it ProjStage5.java
2. Initialize a secretWord
3. In the wordP, add textfields
based on the number of
characters in the secretWord.
Hint:
use array of textfields for easy
manipulation later
Time:
Student No.: _______________ Name: ________________________________________
6
4. Set the textfield as non editable
5. Below the textfield, add buttons
with labels of character "A" to
"Z".
Hint:
use array of buttons for easy
manipulation later
Check:
The output should look similar to the figure below.
Figure 5
Stage 6
Purpose: To handle event for guess a word game
Stage output: An application with the word game.
Task Remarks Evaluation
1. Make a copy of ProjStage5.java
and name it ProjStage6.java
2. Handle the event as follows. When
the user clicked a button
a. Check if the character is in the
secretWord
Hint:
use array of textfields for easy
manipulation later
Time:
Student No.: _______________ Name: ________________________________________
7
b. if yes, display the character in
the textfield
c. disable the button
d. repeat the above steps until all
character are displayed in the
textfield
e. display massage such as
"Congratulations"
Refer to Figure 6
Check:
The output should look similar to the figure below.
Figure 6
Student No.: _______________ Name: ________________________________________
8
Stage 7
Purpose: To have a list of words to guess
Stage output: An application with a more flexible word game
Task Remarks Evaluation
1. Make a copy of ProjStage6.java
and name it ProjStage7.java
2. Create a JComboBox with 3 items
("word1", "word2", "word3")
3. Replace the radiobutton ("Word
game") with the comboBox
4. Initialize (3) secret word lists. Use
array for easy manipulation later
5. Modify your program. Test for
program correctness for all the
secret words
6. Test your program, it should work
correctly when user select a new
word.
Hint:
Test the variable initialization,
resets all textfields and activate
all buttons
Check:
The output should look similar to the figure below.
Figure 7
Time:

 Answer following Question:

Project :  Project_Worksheet.pdf

Write programs in stages as described in the worksheet.

Bonus :

Create an additional page of math or word game.

Initial file : Project.java

import javax.swing.*;
import java.awt.*;

class Project extends JFrame {
Container pane;
JPanel mainP;

public Project() {
pane = getContentPane();
pane.setBackground(Color.white);
pane.setLayout(new BorderLayout());
mainP = new JPanel();
mainP.setBackground(Color.white);
mainP.setLayout(new GridLayout(2, 1));
JLabel welcome = new JLabel("W E L C O M E", JLabel.CENTER);
mainP.add(welcome);
JLabel title = new JLabel("Java Math & Word Games", JLabel.CENTER);
mainP.add(title);
pane.add(mainP, BorderLayout.CENTER);
}

public static void main(String [] args) {
Project frame = new Project();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Java Math & Word Games");
frame.setSize(700, 700);
frame.setVisible(true);
}
}

Upload Required File to completed the Task

Individual Task

GUI & Event例子的更多相关文章

  1. Babylon.GUI官方文档翻译

    Babylon.GUI是一个基于Babylon.js的WebGL库,可以用来在WebGL3D场景中生成交互性UI与动态纹理.相比于html ui,Babylon.GUI的功能较为简化,但使用起来也更加 ...

  2. 处理事件的方式:两种类的覆盖处理(自己管理,覆盖专用事件函数;自己统一管理,覆盖QWidget::Event通用函数),一种对象的处理(父控件统一管理,即安装过滤器),两种全局处理(QCoreApplication安装过滤器;覆盖notify方法)

    虽然只有一句话,但却是我自己的心得. 特别注意,bool QCoreApplication::notify(QObject *receiver, QEvent *event) 明确指明了要发送的对象, ...

  3. Chrome插件Visual Event查看Dom元素绑定事件的利器

    找这工具找了好久,统一找着了,开发人员不可多得的好东东,收藏做一下分享. 用Chrome插件Visual Event查看Dom绑定的事件 Visual Event简介 Visual Event是一个开 ...

  4. Python的GUI用法1

    代码: #python GUI的例子1 import tkinter as tk class Window: def __init__(self,master): frame = tk.Frame(m ...

  5. Visual Event :快速查看 DOM 上绑定的 JS 事件

    http://web.jobbole.com/82503/ Javascript中的事件经常被认为如谜一般不可解.Javascript是一个事件驱动的语言,在这样的前提下前面的看法是很奇怪,但是说到它 ...

  6. Chapter 1. Hello, Perl/Tk

    Chapter 1. Hello, Perl/Tk 内容: Perl/Tk Concepts Some Perl/Tk History Getting Started with Perl/Tk Hel ...

  7. unity 面试题(答案)

    一.什么是渲染管道?是指在显示器上为了显示出图像而经过的一系列必要操作.渲染管道中的很多步骤,都要将几何物体从一个坐标系中变换到另一个坐标系中去.主要步骤有:本地坐标->视图坐标->背面裁 ...

  8. 史上最全的Unity面试题(持续更新总结。。。。。。) 包含答案的Unity面试题

    这个是我刚刚整理出的Unity面试题,为了帮助大家面试,同时帮助大家更好地复习Unity知识点,如果大家发现有什么错误,(包括错别字和知识点),或者发现哪里描述的不清晰,请在下面留言,我会重新更新,希 ...

  9. 15_游戏编程模式EventQueue

    #### 两个例子 .GUI event loop ``` while (running) { // 从事件队列里获取一个事件 Event event = getNextEvent(); // Han ...

随机推荐

  1. 移植一个开源点餐网到SAE平台上

    记得以前我准备弄个点餐网的,但是由于一些原因没有做下去. 前几天将网上的一个点餐源码移植到了SAE上,网址http://diancan4sae.sinaapp.com. 我想做个外卖网,先选一个学校周 ...

  2. 代码静态分析工具PC-LINT安装配置

    代码静态分析工具PC-LINT安装配置--step by step                             作者:ehui928                             ...

  3. (四)SAX方式解析XML数据

    SAX方式解析XML数据 ​文章来源:http://www.cnblogs.com/smyhvae/p/4044170.html 一.XML和Json数据的引入: 通常情况下,每个需要访问网络的应用程 ...

  4. Android常用控件之RatingBar的使用

    RatingBar控件比较常见就是用来做评分控件,先上图看看什么是RatingBar 在布局文件中声明 <?xml version="1.0" encoding=" ...

  5. ASI简单实现网络编程

    使用iOS SDK中的HTTP网络请求API,相当的复杂,调用比較麻烦.ASIHTTPRequest 对CFNetwork API进行了封装.而且使用起来非常easy的一套API,在非常多比較老旧的项 ...

  6. Android 表格布局<TableLayout>

    表格布局即,tableLayout,表格布局通过行.列的形式来管理UI组件,TablelLayout并不需要明确地声明包含多少行.多少列,而是通过TableRow,以及其他组件来控制表格的行数和列数, ...

  7. Win8下在Vmware11中安装使用苹果系统OS X 10.10

    原文:Win8下在Vmware11中安装使用苹果系统OS X 10.10   近来因为需要做 iOS 的项目,所以需要多花一些时间看看敲敲代码.因为自己手头上并没有 Mac(过年为了闲的时候能玩玩游戏 ...

  8. SharePoint 内容部署-PowerShell

    1. 创建一个新的内容部署路径 New-SPContentDeploymentPath –Name "Marketing Internet Content" –SourceSPWe ...

  9. OCA读书笔记(14) - 备份和恢复基本概念

    备份恢复概念 如何判断数据库的一致性 在mount状态下,oracle如何判断数据库的一致性 scn:system change number,它是数据库时钟 如何查询当前系统的scn: select ...

  10. JMX操作ActiveMQ(1)

    我们知道ActiveMQ broker的管理接口是通过JMX方式提供的. 一个简单的访问方式就是通过jconsole,输入 service:jmx:rmi:///jndi/rmi://localhos ...