I kind of like the text and the general feeling!
Here is a very simple and quickly made GUI with comments on how to use it!
package test;
import java.awt.Dimension;
import javax.swing.*;
//By Skarion
public class ScWindow extends JFrame{
private JPanel view;
public ScWindow(int width, int height){
setTitle("Fight for Arcadia");
Dimension d = new Dimension(width, height);
setSize(d);
setPreferredSize(new Dimension(d));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void setContentPane(JPanel view){
super.setContentPane(this.view = view);
pack();
setVisible(true);
}
public static void main(String[] args){
//Example of how to use these classes.
char newLine = 10;
View v = new View();
v.setTitle("Main menu");
v.setText("FIGHT FOR ARCADIA (now in HD)"+newLine+"Copyright (c) 2011 Robert M."+newLine+"Version 0.8 - 15 Sep 2011");
v.setEvents(new Event("New Game"), new Event("Load Game"),new Event("Help"),new Event("Exit"));
ScWindow s = new ScWindow(300,400);
s.setContentPane(v);
}
}
package test;
import java.awt.*;
import java.util.HashMap;
import javax.swing.*;
//By Skarion
public class View extends JPanel{
private JLabel title;
private JTextArea text;
private JPanel south;
private static int MAXEVENTS=6;
public View(){
super(new BorderLayout());
title = new JLabel();
title.setFont(new Font("Verdana",Font.PLAIN,20));
text = new JTextArea();
text.setEditable(false);
text.setBackground(null);
south = new JPanel(new GridLayout(MAXEVENTS,1));
Dimension d = new Dimension(200,30*MAXEVENTS);
south.setSize(d);
south.setPreferredSize(d);
add(title, BorderLayout.NORTH);
add(text, BorderLayout.CENTER);
add(south, BorderLayout.SOUTH);
}
public void setTitle(String s){
title.setText(s);
}
public void setText(String s){
text.setText(s);
}
public void setEvents(Event... events){
south.removeAll();
if(events.length>MAXEVENTS){
System.out.println("You need to declare a larger MAXEVENTS to do this, else it will get ugly!");
}
for(int i = 0;i<events.length;i++){
events[i].setSelected(i);
JButton event = new JButton(events[i].getText());
event.addMouseListener(events[i]);
south.add(event);
}
updateUI();
}
}
package test;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
//By Skarion
public class Event extends MouseAdapter{
private int value;
private String text;
//private Model model;
public Event(String text /*, Model model*/){
//Send in the model here for usage.
//this.model = model;
this.text = text;
}
public String getText(){
return text;
}
public void setSelected(int value){
this.value = value;
}
public void mousePressed(MouseEvent e){
//Tell model to activate this event.
//model.eventFired(value);
}
}
If there is anything you wonder or would like to know, post and I can see if I can fix it.