Search in sources :

Example 1 with GameFrame

use of org.drools.games.GameFrame in project drools by kiegroup.

the class GameUI method initialize.

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frame = new GameFrame("Wumpus World");
    frame.getContentPane().setBackground(Color.WHITE);
    frame.setDefaultCloseOperation(wumpusWorldConfiguration.isExitOnClose() ? JFrame.EXIT_ON_CLOSE : JFrame.DISPOSE_ON_CLOSE);
    frame.setLayout(new MigLayout("", "[540px:n][grow,fill]", "[30px,top][300px,top][100px,top][grow]"));
    frame.setSize(926, 603);
    // Center in screen
    frame.setLocationRelativeTo(null);
    JPanel scorePanel = new JPanel();
    FlowLayout flowLayout = (FlowLayout) scorePanel.getLayout();
    flowLayout.setAlignment(FlowLayout.LEFT);
    scorePanel.setBackground(Color.WHITE);
    frame.getContentPane().add(scorePanel, "cell 0 0,grow");
    JLabel lblScore = new JLabel("Score");
    scorePanel.add(lblScore);
    final JTextField txtScore = new JTextField();
    gameView.getKsession().getChannels().put("score", new Channel() {

        public void send(Object object) {
            txtScore.setText("" + ((Score) object).getValue());
        }
    });
    txtScore.setEditable(false);
    scorePanel.add(txtScore);
    txtScore.setColumns(10);
    JScrollPane scrollPane = new JScrollPane();
    frame.getContentPane().add(scrollPane, "cell 1 0 1 4,grow");
    JPanel actionPanel = new JPanel();
    actionPanel.setBackground(Color.WHITE);
    frame.getContentPane().add(actionPanel, "cell 0 1,grow");
    actionPanel.setLayout(new MigLayout("", "[200px,left][320px:n]", "[grow]"));
    JPanel controls = new JPanel();
    controls.setBackground(Color.WHITE);
    controls.setLayout(new MigLayout("", "[grow,fill]", "[::100px,top][200px,top]"));
    controls.add(drawActionPanel(), "cell 0 0,alignx left,aligny top");
    controls.add(drawMovePanel(), "cell 0 1,alignx left,growy");
    actionPanel.add(controls, "cell 0 0,grow");
    cavePanel = drawCave();
    actionPanel.add(cavePanel, "cell 1 0,grow");
    sensorPanel = drawSensorPanel();
    frame.getContentPane().add(sensorPanel, "cell 0 2,grow");
    JPanel blank = new JPanel();
    blank.setBackground(Color.WHITE);
    frame.add(blank, "cell 0 3,grow");
    frame.setVisible(true);
    cavePanel.getBufferedImage();
    sensorPanel.getBufferedImage();
    repaint();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GameFrame(org.drools.games.GameFrame) MigLayout(net.miginfocom.swing.MigLayout) Channel(org.kie.api.runtime.Channel) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField)

Aggregations

JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTextField (javax.swing.JTextField)1 MigLayout (net.miginfocom.swing.MigLayout)1 GameFrame (org.drools.games.GameFrame)1 Channel (org.kie.api.runtime.Channel)1