Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A quick demonstration of the MVC pattern.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class EmployeeClient {
public static void main(String[] args) {
EmployeeView view = new EmployeeView();
EmployeeModel model = new EmployeeModel();
EmployeeController cntlr = new EmployeeController(view, model);;
class EmployeeModel {
private String[] names = { "Ryan", "Mike", "Joe" };
private int index;
public EmployeeModel() {
public String getNextName() {
return names[index++ % names.length];
class EmployeeController implements ActionListener {
private EmployeeView view;
private EmployeeModel model;
public EmployeeController(EmployeeView v, EmployeeModel m) {
view = v;
model = m;
public void actionPerformed(ActionEvent e) {
class EmployeeView {
private JFrame win;
private JPanel frm;
private JLabel name;
private JButton action;
public EmployeeView() {
win = new JFrame("Employee Form");
frm = new JPanel();
name = new JLabel("Empty");
action = new JButton("Next Employee");
frm.setLayout(new BoxLayout(frm, BoxLayout.Y_AXIS));
public void setName(String name) {;
public void setController(ActionListener cntlr) {
public void open() {
win.setSize(300, 300);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment