联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2025-06-23 08:56

Laboratory work #4 | Data model in application

Objectives

The goal of this laboratory work is to learn, how to implement GUI application based on an object-oriented method

of task analysis and decomposition involving data models.

Instructions

Create a program capable of managing data items of some domain (see variants). Use different Swing UI controls to

organize graphical user interface. The user should be able to

add new elements of data,

modify selected element of data,

or remove existing elements of data

filter displayed elements from the whole content of the internal collection.

Each element of data consists of a few trivial fields carrying the literal values according to the domain case.

Steps:

1. Create a main class having entry point

2. Implement internal task domain classes

a. Create a class representing domain’s element of data having fields suggested in the variant,

methods for reading and changing values of these fields, constructor for newly created data

element initialization.

b. Create a domain model class having at least field with collection of elements of data and methods

for each operation, described in the variant, including: add new element, remove existing element,

extract subset of elements according to the given condition, change fields of the existing element.

3. Create a class implementing the window displaying the content described below:

a. An area with brief visualization of the data collection without details for each item

(use UI control of JList, JTable and JTree according to your variant, implement data model if needed)

b. An area displaying non-editable details about the element being selected in the collection

(use a number of different UI controls like JLabel, JCheckBox, JRadioButton, JComboBox, JTextField,

JTextArea for each data field of the selected element)

c. An area with a number of buttons, each for a different operation to perform with data or its

representation

4. Implement a logic responsible for performing operations by ActionListeners for each operation-related

button (created during step 3c) so that the window class itself holds a reference to the domain model class

(created during step 2b) and each action event listener uses its methods to perform corresponding internal

operation and update the state of the UI controls. Each variant has clarifications about some operations.

Operations of each (a, b, c, d) kind should be implemented, even if some of them are not mentioned in the

variant explicitly (editing for example):

a. Implement operation for a user to add a new element of data, the element being added should not

be displayed as part of the collection until the user confirms its creation or cancels the operation.

b. Implement operation for a user to edit selected element of data with options to cancel editing or

preserve the modifications.

c. Implement operation for a user to delete selected element of data with confirmation message, so

that it would be possible to cancel the operation.

d. Implement operation for a user to filter the elements being displayed according to some data fields.

Editing operations should continue to work correctly for a data displayed when the filter is in use.

Solution requirements:

 The application process should be correctly terminated when the window being closed.

 Initial window size should be correctly prepared.

 Use layout managers of your choice for automatic UI controls arrangement according to the window being

resized by the user.

 When the program starts, internal collections contain no data. Data persistence is not discussed in this lab.

Variants

Each variant described with four numbers: A, B, C, D.

A – case number, B – main window layout, C – UI control for collection, D – way of editing implementation.

For example, variant “1, 2, 3, 1” means use domain case 1 (contact list), use layout sketch #2 (vertical orientation),

use JTree to visualize and navigate the collection, implement editing operations in the same main window by

switching details view into editable mode.

Main window layout sketches (for step 3):

UI control to use for a brief collection visualization (see step 3a):

Number UI control

1 JList

2 JTable

3 JTree

Lab3, StudentName, #IdNumber

Lab3, StudentName, #IdNumber

Lab3, StudentName, #IdNumber

Collection View

and

filter parameters Details View

Editing operations Delete Edit Add

Collection View

and

filter parameters Details View

Editing ops Delete

Edit Add

Collection View

and

filter parameters

Details View

Editing operations Delete Edit Add

Way of editing implementation:

1. In the same main window by switching details view into editable mode

(see setEditable(..) and setEnabled(..) methods of the UI controls)

2. In the separate dialog window implemented by inheriting from JDialog class

Domain case

1. Contact-list

Operations to support: search for a contact, add new contact, exit from the program.

New contact addition performed by entering the information elements such as: name, surname, telephone number,

email and so on.

Contact searching could be performed by name or by phone number, or by name and surname, or by all fields at

once. After selection of the search mode, user should enter desired string (part of the phone number or such), that

would be used during search, and information of the corresponding conracts should be printed.

2. Todo-list

Operations to support: create todo-item, search todo-items by tags, filter actual todo-items.

Item creation procedure requires item title, description, deadline date and tags. Tags could be handled in UI as one

text field, while being represented as array of separate tags internally.

Search by tags starts from the request of the keywords to search from the user. User enters them using space

separator. Then, if some todo-item has one of the given tags, such item should be filtered.

Actual todo-items output should be performed for the requested number of items considering them in the order of

deadline date growth.

3. Library catalog

Information about book consists of title, author name, annotation, ISBN and publication date.

Operations to support: add book to the catalog, get book information by its ISBN, search book by any keywords.

Search operation should display brief book descriptions (without annotation) in the order of decreasing the number

of keywords found. If a particular keyword found in the annotation, reflect this fact during the output.

4. Playlist manager

Operations to support: search composition by a certain criterion, show all compositions from the playlist, add new

composition to the playlist, remove composition from the playlist.

The search criteria can be: name author of composition or the title of composition.

As a result of the search, the list of the compositions should be shown, having “number – author – title – duration”

for each composition. Removal of composition requires its number. Addition requires entering all information about

the composition.

5. Shopping-list

Shopping list contains list of the purchases performed. Each item has name, comment, amount of credits spent, and

date of purchase.

Operations to support: add new purchase info, remove purchase by its number, print purchases in the specified

range of dates.

6. Cookbook

Each recipe in the cookbook represented with title, brief description, and number of steps to cook.

Operations to support: add new recipe, delete recipe by name, search for the recipe.

Recipe search performed by any word contained in its title, description or steps and results with list of detailed

description of corresponding recipes.

7. Gradebook

Gradebook is the book with information about students’ marks: it helps to the teacher (and student) answer two the

question about the marks by the subjects.

Technically, the book – is a set of records that combines information about the student (name), subject and mark.

Operations to support: add new grade mark item, delete the item by student’s and subject name, search by the

subject (to display marks by this subject for all students).

8. Meteorological log

It is a journal with information about the meteorological data: temperature, pressure, precipitation (rain, snow) in

particular date/time.

Operations to support with the log: add new item, delete the item by date, show the list of data by month.

9. Discount journal

It is a journal with information about your discounts in different markets (like Stocard application for smartphones).

It stores information about the shop, size of discount and the discount’s expiration date.

Operations to support: add new item, delete the item by shop, show the list of your discounts sorted by the

alphabet.

Extra information

Brief overview of some Swing classes to know about:

● Basic containers and windows

JFrame

JDialog

JPanel

JSplitPane

JOptionPane

● Layout managers

BorderLayout

BoxLayout

CardLayout

FlowLayout

GridBagLayout

GridLayout

GroupLayout

SpringLayout

● Basic controls

JLabel

JButton

JCheckBox

JRadioButton

JList

JComboBox

JTextField

JScrollBar

JSlider

● Advanced controls

JScrollPane

JTextArea

JTable

JTree

Brief overview of some IO classes to know about:

● Writer classes

FileWriter

OutputStreamWriter

BufferedWriter

StringWriter

● OutputStream classes

DataOutputStream

BufferedOutputStream

ByteArrayOutputStream

FileOutputStream

PrintStream

● Reader classes

FileReader

InputStreamReader

BufferedReader

StringReader

● InputStream classes

DataInputStream

BufferedInputStream

ByteArrayInputStream

FileInputStream

● Parsing and formatting

Scanner

Formatter

ByteBuffer

● File system management

java.io.File

java.nio.file.Path

java.nio.file.Files


相关文章

【上一篇】:到头了
【下一篇】:没有了

版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp