Case study · Java SE · 2019
A box-office console for cinema staff. Three Swing windows call a server over Java RMI, and the server keeps films, screenings and tickets in MySQL through JPA.


A client–server desktop application, built as the final project of the Java 2 course at university. The cashier works in three small windows, and every button is a remote call to one server that owns the database.
Add a film with its title, length, genre and cast, list the programme and remove a film by its ID.
Schedule a film on a date in one of three halls, from 150 down to 80 seats, and cancel a screening.
Pick a screening, type the customer's name and contact details, and sell the ticket. Every sale appears in the ticket list.
A small cinema runs on three lists: the films in its programme, the screenings scheduled in each hall, and the tickets sold at the desk. Kept in a spreadsheet on one computer, they are out of date the moment a second cashier opens.
This application moves the lists to a server. Each desk runs a light Swing client, and every click is a remote method call over Java RMI. The server stores everything in MySQL through JPA, so all desks see the same programme. It was my final project for the Java 2 course, built to practise distributed objects and object-relational mapping in one real app.

This is the cashier's desktop, rebuilt for the web from the original code, with the same windows, dialogs and messages. Add or delete a film, open Screenings to schedule a screening, or open Tickets to sell a ticket. The log on the right shows each remote call and the SQL that EclipseLink ran for it, taken from a real run of the server.
Films
One remote call: from a button in a Swing frame, across RMI, through JPA into MySQL and back
On start, the server creates an RMI registry on port 1234 and binds one service object under the name filmService.
The client fetches a stub for that name once, the first time any window needs data.
A button calls a method on the stub. RMI serialises the arguments, runs the method on the server and sends the result back.
The server opens an EntityManager, lets a DAO do the work and commits the transaction to MySQL.
SHARED
The contract: the remote interface and the five entity classes. Both sides compile against it, and every entity is Serializable so it can cross the wire.
MODULE
The registry, the service implementation, one DAO per entity and the JPA persistence unit. It is the only part that touches the database.
MODULE
Three JFrames and three form panels designed in the NetBeans GUI Builder, plus the controller that holds the RMI stub.
STORAGE
One schema, java2project, recreated by EclipseLink from the entities every time the server starts.
Everything the client can do is declared in one interface, FilmService, which extends java.rmi.Remote. It has eight methods: add, list and delete for films and screenings, and sell and list for tickets. Three of them were bonus points in the brief.
Every method declares RemoteException, because any call can fail on the network. The client never sees the implementation class, only this interface and a generated stub that forwards each call to the server.
lib · rmi/FilmService.javapublic interface FilmService extends Remote {
void addFilm(Film f) throws RemoteException;
List<Film> listFilms() throws RemoteException;
void deleteFilm(int id) throws RemoteException;
void addScreening(Screening d) throws RemoteException;
List<Screening> listScreenings() throws RemoteException; //BONUS
void deleteScreening(int id) throws RemoteException; //BONUS
void sellTicket(Spectator s) throws RemoteException;
List<Spectator> listTickets() throws RemoteException; //BONUS
}
server · Server.java + client · ClientController.java// server: publish one remote object under a name
Registry reg = LocateRegistry.createRegistry(1234);
FilmService filmService = new FilmServiceImpl();
reg.rebind("filmService", filmService);
// client: look it up once, behind a lazy singleton
private ClientController() {
Registry reg = LocateRegistry.getRegistry(1234);
filmService = (FilmService) reg.lookup("filmService");
}
private static final class SingletonHolder {
private static final ClientController instance = new ClientController();
}
Wiring the two sides takes three lines on the server and two on the client. The server publishes the service in its own registry, and the client looks it up by name.
The client keeps the stub in a ClientController singleton, created lazily with the holder idiom. Each window asks the controller for data, and the controller wraps every remote call in a try/catch, so a lost connection prints a stack trace instead of closing the app.
server · service/FilmServiceImpl.javapublic class FilmServiceImpl extends UnicastRemoteObject implements FilmService {
private EntityManagerFactory emf =
Persistence.createEntityManagerFactory("Project-serverPU");
@Override
public void addFilm(Film f) {
EntityManager em = emf.createEntityManager(); // one per call
FilmDao filmDao = new FilmDao(em);
try {
em.getTransaction().begin();
filmDao.addFilm(f); // em.persist(f)
em.getTransaction().commit();
} finally {
em.close();
}
}
}
RMI
The implementation extends it, so it is exported as soon as it is created and listens for calls on its own port.
CONCURRENCY
Each call runs on an RMI TCP Connection thread, so two desks can be served at the same time.
JPA
One shared, thread-safe factory, and a fresh EntityManager for every call, so desks never share a persistence context.
TRANSACTION
Writes run in a transaction and close the EntityManager in finally, whether the commit succeeds or not.
There is no SQL script in the project. EclipseLink reads the annotations on four entities and generates five tables, dropping and recreating them on every start. The cast of a film becomes a separate Film_ACTORS table, and a ticket buyer's Contact is embedded in the SPECTATOR row.
The schema EclipseLink generated: two foreign keys, one title copied as text, and a stand-alone ticket table
lib · entities, condensed@Entity
public class Film implements Serializable {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String title;
private int duration;
@Enumerated(EnumType.STRING)
private Genre genre; // COMEDY, DRAMA, HORROR, TRAGEDY
@ElementCollection
private List<String> actors;
}
@Entity
public class Screening implements Serializable {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String film; // the title, not a relation
@Temporal(TemporalType.DATE)
private Date date;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "hall_id")
private Hall hall;
}
generated by EclipseLink · drop-and-createCREATE TABLE SCREENING (ID INTEGER AUTO_INCREMENT NOT NULL, DATE DATE,
FILM VARCHAR(255), hall_id INTEGER, PRIMARY KEY (ID))
CREATE TABLE FILM (ID INTEGER AUTO_INCREMENT NOT NULL, DURATION INTEGER,
GENRE VARCHAR(255), TITLE VARCHAR(255), PRIMARY KEY (ID))
CREATE TABLE HALL (ID INTEGER AUTO_INCREMENT NOT NULL, NAME VARCHAR(255),
SEATS INTEGER, PRIMARY KEY (ID))
CREATE TABLE SPECTATOR (ID INTEGER AUTO_INCREMENT NOT NULL, NAME VARCHAR(255),
EMAIL VARCHAR(255), PHONE VARCHAR(255), PRIMARY KEY (ID))
CREATE TABLE Film_ACTORS (Film_ID INTEGER, ACTORS VARCHAR(255))
ALTER TABLE SCREENING ADD CONSTRAINT FK_SCREENING_hall_id
FOREIGN KEY (hall_id) REFERENCES HALL (ID)
ALTER TABLE Film_ACTORS ADD CONSTRAINT FK_Film_ACTORS_Film_ID
FOREIGN KEY (Film_ID) REFERENCES FILM (ID)
ENTITY
Title, length in minutes, a genre stored by name, and an @ElementCollection of actors.
ENTITY
A screening: the film title, a date and a hall, saved together through cascade = ALL.
ENTITY
A hall with a name and a seat count: Hall 1 has 150 seats, Hall 2 120 and Hall 3 80.
ENTITY
The ticket buyer: a name and an @Embedded contact with email and phone, in the same row.
The client is plain Swing with the default Metal look. Each window is a JFrame with a column of buttons and a JList, and every form is a JPanel shown inside a JOptionPane, so OK, Cancel and the messages come for free. These are real screenshots, taken by running the code with its interface translated to English.

FILMS
The main window. Refresh, add and delete films, and open the other two windows.

SCREENINGS
Every screening with its film, date and hall.

TICKETS
Every ticket sold, by the customer's name. Sell opens the sale form.

ADD
Title, length, a genre list and the cast, separated by commas.

ADD
Films come from the server. Day, month and hall are lists.

DELETE
Deleting asks for the ID shown in the list, then confirms with a message.
Sell opens a form with every screening in a drop-down, labelled with its film, date and hall. The cashier types the customer's name, email and phone and presses OK.
The client fetches the screenings again and builds a Spectator with the name. One remote call, sellTicket, sends it to the server, which inserts it in one transaction. A message confirms the sale and the ticket list refreshes. Looking back at the code, two lines never did what they were meant to, and the log in the demo shows both.


client · gui/TicketFrame.java · sellTickets()List<Screening> screeningList = ClientController.getInstance().listScreenings();
String selectedScreening = sellTicketPanel.getJComboBox1();
for (Screening x : screeningList) {
if (x.getFilm().equals(selectedScreening)) { // "Joker" vs "ID: 1 Film: JOKER ..."
screening = x;
}
}
Contact c = new Contact();
c.setEmail(email);
c.setPhone(phone);
Spectator s = new Spectator();
s.setName(name);
// s.setContact(c);
ClientController.getInstance().sellTicket(s);
JOptionPane.showMessageDialog(this, "Spectator added successfully!");
1
The drop-down shows each screening's toString(), so the cashier sees the film, the date and the hall.
2
The loop compares a title with that full label, so it never matches, and the result is not used anyway.
3
The email and phone are read, but setContact is commented out, so both columns stay NULL.
4
One INSERT into SPECTATOR, a confirmation and a refreshed list. The sale itself always works.
CONFIG
One persistence unit, Project-serverPU, with the EclipseLink provider, the MySQL connection and drop-and-create schema generation.
JAVA
FilmDao, ScreeningDao and SpectatorDao wrap persist, find and remove, and list with JPQL queries such as SELECT f FROM Film f.
SWING
Every window and form was laid out in the NetBeans designer. Its .form files are still in the project next to the code.
TODAY
For this page, I translated the interface from Romanian to English, ran the code with H2 in MySQL mode instead of a MySQL server, and rendered the real windows to images.
A working three-tier desktop app: a Swing client, an RMI server and a MySQL database, with eight remote methods, a schema generated from annotations, and several desks sharing the same data.
Seats are not counted: only each hall's capacity is stored. A ticket is not linked to its screening, the contact is not saved, every screening creates a new hall row, the year is fixed to 2019, inputs are not validated, and list calls never close their EntityManager.
Turn the server into a Spring Boot REST API with Spring Data JPA, make Ticket a real entity linked to a screening and a seat, reuse a fixed set of halls, and replace the lists with a clickable seat map so the cashier can see what is still free.