Skip to content

Commit

Permalink
Using AbsoluteLayout (null layout)
Browse files Browse the repository at this point in the history
  • Loading branch information
teamon committed Nov 22, 2010
1 parent 5a0f7f3 commit 3f6d170
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 49 deletions.
96 changes: 47 additions & 49 deletions src/main/java/eu/teamon/volley/ClientFrame.java
@@ -1,6 +1,7 @@
package eu.teamon.volley;

import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.awt.*;
import java.io.IOException;
Expand All @@ -23,72 +24,69 @@ public class ClientFrame extends JFrame {
private Client client;

public ClientFrame() {
setTitle("Volley Client");
setTitle("Volley Client");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

Container pane = getContentPane();
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));


JPanel settingsPane = new JPanel();
settingsPane.setLayout(new FlowLayout());

setBounds(100, 100, 722, 474);

JPanel pane = new JPanel();
pane.setBorder(new EmptyBorder(5, 5, 5, 5));
pane.setLayout(null);
setContentPane(pane);

JPanel settingsPanel = new JPanel();
settingsPanel.setBorder(new TitledBorder(null, "Settings", TitledBorder.LEADING, TitledBorder.TOP, null, null));
settingsPanel.setBounds(406, 6, 310, 139);
settingsPanel.setLayout(null);
pane.add(settingsPanel);

// port
portLabel = new JLabel();
portLabel.setText("Port:");
portLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
settingsPane.add(portLabel);
portLabel = new JLabel("Port:");
portLabel.setHorizontalAlignment(SwingConstants.RIGHT);
portLabel.setBounds(17, 50, 61, 16);
settingsPanel.add(portLabel);

portTextField = new JTextField();
portTextField.setPreferredSize(new Dimension(50, 30));
portTextField.setBounds(90, 44, 213, 28);
portTextField.setText("7777");
portTextField.setAlignmentX(Component.CENTER_ALIGNMENT);
settingsPane.add(portTextField);

settingsPanel.add(portTextField);

// host
hostLabel = new JLabel();
hostLabel.setText("Host:");
hostLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
settingsPane.add(hostLabel);
hostLabel = new JLabel("Host:");
hostLabel.setHorizontalAlignment(SwingConstants.RIGHT);
hostLabel.setBounds(17, 22, 61, 16);
settingsPanel.add(hostLabel);

hostTextField = new JTextField();
hostTextField.setPreferredSize(new Dimension(250, 30));
hostTextField.setText("");
hostTextField.setAlignmentX(Component.CENTER_ALIGNMENT);
settingsPane.add(hostTextField);

hostTextField.setBounds(90, 16, 213, 28);
settingsPanel.add(hostTextField);

// nick
nickLabel = new JLabel();
nickLabel.setText("Nick:");
nickLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
settingsPane.add(nickLabel);
nickLabel = new JLabel("Nick:");
nickLabel.setHorizontalAlignment(SwingConstants.RIGHT);
nickLabel.setBounds(17, 78, 61, 16);
settingsPanel.add(nickLabel);

nickTextField = new JTextField();
nickTextField.setPreferredSize(new Dimension(250, 30));
// nickTextField.setText("");
nickTextField.setAlignmentX(Component.CENTER_ALIGNMENT);
settingsPane.add(nickTextField);

nickTextField.setBounds(90, 72, 213, 28);
settingsPanel.add(nickTextField);

connectButton = new JButton();
connectButton.setText("Connect");

connectButton = new JButton("Connect");
connectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(client == null){
connect();
} else {
disconnect();
}

}
});
connectButton.setAlignmentX(Component.CENTER_ALIGNMENT);
settingsPane.add(connectButton);
connectButton.setBounds(100, 104, 117, 29);
settingsPanel.add(connectButton);


pane.add(settingsPane);
pane.add(settingsPanel); // TODO: Extract settingsPanel into separate class
pane.add(new GamePanel());

// Chat

pack();
// pack();
}


Expand Down
17 changes: 17 additions & 0 deletions src/main/java/eu/teamon/volley/GamePanel.java
@@ -0,0 +1,17 @@
package eu.teamon.volley;

import java.awt.*;
import java.awt.event.*;
import javax.swing.JPanel;

public class GamePanel extends JPanel {

public GamePanel(){
setSize(300, 300);
}

public void paintComponent(Graphics g){
g.setColor(Color.red);
g.drawRect(50, 50, 200, 250);
}
}

0 comments on commit 3f6d170

Please sign in to comment.