Begin launcher in Swing. This, surprisingly, is the easy part, because I'm not trying to do it in C#.
parent
566a33fdc4
commit
4a3f6f2a7c
|
@ -12,5 +12,6 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="forms-1.3.0.jar" sourcepath="forms-1.3.0-src.zip"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,161 @@
|
|||
package net.mosstest.launcher;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.GridLayout;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
|
||||
public class GUIClientsideLauncher {
|
||||
|
||||
public class SingleplayerListEntry {
|
||||
|
||||
public String name;
|
||||
public String description;
|
||||
public String gamePreset;
|
||||
|
||||
public SingleplayerListEntry(String name, String description,
|
||||
String gamePreset) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.gamePreset = gamePreset;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private JFrame frame;
|
||||
private JTable table;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (ClassNotFoundException | InstantiationException
|
||||
| IllegalAccessException | UnsupportedLookAndFeelException e1) {
|
||||
System.out
|
||||
.println("[ERROR] [NONFATAL] [GUI] System Look-And-Feel could not be set; falling back to default L&F.");
|
||||
}
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
GUIClientsideLauncher window = new GUIClientsideLauncher();
|
||||
window.frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the application.
|
||||
*/
|
||||
public GUIClientsideLauncher() {
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the contents of the frame.
|
||||
*/
|
||||
private void initialize() {
|
||||
this.frame = new JFrame();
|
||||
this.frame.setBounds(100, 100, 800, 480);
|
||||
this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
this.frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
||||
|
||||
JPanel singleplayerTab = new JPanel();
|
||||
tabbedPane.addTab("Singleplayer", null, singleplayerTab, null);
|
||||
singleplayerTab.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JPanel singleplayerControlBtns = new JPanel();
|
||||
singleplayerTab.add(singleplayerControlBtns, BorderLayout.SOUTH);
|
||||
singleplayerControlBtns.setLayout(new GridLayout(0, 4, 0, 0));
|
||||
|
||||
JButton btnPlaySingleplayer = new JButton("Play");
|
||||
singleplayerControlBtns.add(btnPlaySingleplayer);
|
||||
|
||||
JButton btnNewSingleplayer = new JButton("New...");
|
||||
|
||||
singleplayerControlBtns.add(btnNewSingleplayer);
|
||||
|
||||
JButton btnSettingsSingleplayer = new JButton("Settings...");
|
||||
singleplayerControlBtns.add(btnSettingsSingleplayer);
|
||||
|
||||
JButton btnDelete = new JButton("Delete...");
|
||||
singleplayerControlBtns.add(btnDelete);
|
||||
|
||||
this.table = new JTable();
|
||||
this.table.setModel(new SingleplayerListTableModel());
|
||||
this.table.getColumnModel().getColumn(0).setPreferredWidth(90);
|
||||
this.table.getColumnModel().getColumn(1).setPreferredWidth(256);
|
||||
this.table.getColumnModel().getColumn(2).setPreferredWidth(104);
|
||||
this.table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
singleplayerTab.add(this.table, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
class SingleplayerListTableModel extends AbstractTableModel {
|
||||
private String[] columnNames = { "World name", "Description",
|
||||
"Game preset" };
|
||||
private ArrayList<SingleplayerListEntry> entries = new ArrayList<>();
|
||||
|
||||
public int getColumnCount() {
|
||||
return this.columnNames.length;
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return this.entries.size();
|
||||
}
|
||||
|
||||
public String getColumnName(int col) {
|
||||
return this.columnNames[col];
|
||||
}
|
||||
|
||||
public Object getValueAt(int row, int col) {
|
||||
SingleplayerListEntry entry = this.entries.get(row);
|
||||
switch (col) {
|
||||
case 0:
|
||||
return entry.name;
|
||||
case 1:
|
||||
return entry.description;
|
||||
case 2:
|
||||
return entry.gamePreset;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* All entries are strings *at the moment*.
|
||||
*/
|
||||
public Class getColumnClass(int c) {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't need to implement this method unless your table's editable.
|
||||
*/
|
||||
public boolean isCellEditable(int row, int col) {
|
||||
// Note that the data/cell address is constant,
|
||||
// no matter where the cell appears onscreen.
|
||||
if (col < 2) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package net.mosstest.launcher;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import com.jgoodies.forms.factories.FormFactory;
|
||||
import com.jgoodies.forms.layout.ColumnSpec;
|
||||
import com.jgoodies.forms.layout.FormLayout;
|
||||
import com.jgoodies.forms.layout.RowSpec;
|
||||
|
||||
public class GUIWorldCreationDialog extends JDialog {
|
||||
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
private JTextField nameField;
|
||||
private JComboBox<String> comboBox;
|
||||
private JTextField inputDesc;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
GUIWorldCreationDialog dialog = new GUIWorldCreationDialog();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public GUIWorldCreationDialog() {
|
||||
setBounds(100, 100, 450, 159);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
this.contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(this.contentPanel, BorderLayout.CENTER);
|
||||
this.contentPanel.setLayout(new FormLayout(new ColumnSpec[] {
|
||||
FormFactory.RELATED_GAP_COLSPEC,
|
||||
FormFactory.DEFAULT_COLSPEC,
|
||||
FormFactory.RELATED_GAP_COLSPEC,
|
||||
ColumnSpec.decode("default:grow"),},
|
||||
new RowSpec[] {
|
||||
FormFactory.RELATED_GAP_ROWSPEC,
|
||||
FormFactory.DEFAULT_ROWSPEC,
|
||||
FormFactory.RELATED_GAP_ROWSPEC,
|
||||
FormFactory.DEFAULT_ROWSPEC,
|
||||
FormFactory.RELATED_GAP_ROWSPEC,
|
||||
FormFactory.DEFAULT_ROWSPEC,}));
|
||||
{
|
||||
JLabel lblWorldName = new JLabel("World name:");
|
||||
this.contentPanel.add(lblWorldName, "2, 2, right, default");
|
||||
}
|
||||
{
|
||||
this.nameField = new JTextField();
|
||||
this.contentPanel.add(this.nameField, "4, 2, fill, default");
|
||||
this.nameField.setColumns(10);
|
||||
}
|
||||
{
|
||||
JLabel lblDescription = new JLabel("Description:");
|
||||
this.contentPanel.add(lblDescription, "2, 4, right, default");
|
||||
}
|
||||
{
|
||||
this.inputDesc = new JTextField();
|
||||
this.contentPanel.add(this.inputDesc, "4, 4, fill, default");
|
||||
this.inputDesc.setColumns(10);
|
||||
}
|
||||
{
|
||||
JLabel lblGameProfile = new JLabel("Game profile:");
|
||||
this.contentPanel.add(lblGameProfile, "2, 6, right, default");
|
||||
}
|
||||
{
|
||||
this.comboBox = new JComboBox<String>(); //todo pass array in with set of games.
|
||||
this.contentPanel.add(this.comboBox, "4, 6, fill, default");
|
||||
}
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton okButton = new JButton("OK");
|
||||
okButton.setActionCommand("OK");
|
||||
buttonPane.add(okButton);
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
{
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue