Suspended
- Joined
- 3 Nov 2002
- Posts
- 3,092
Hello chaps!
I'm trying to desgin the user interface for a paint program in Java. However I am having real trouble trying to get all the buttons and JPanels to a reasonable size, I have tried setSize(), setPreferredSize(), setMaximumSize() and setMinimumSize, all of which seem to have no effect.
I'm trying to desgin the user interface for a paint program in Java. However I am having real trouble trying to get all the buttons and JPanels to a reasonable size, I have tried setSize(), setPreferredSize(), setMaximumSize() and setMinimumSize, all of which seem to have no effect.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class paintprog extends JFrame implements ActionListener
{
Label dude;
JTextField shape, colour, combine;
JButton sqlnbutton, sqflbutton, crlnbutton, crflbutton, hxlnbutton, hxflbutton, linebutton, dashbutton, col1button, col2button, col3button, col4button, col5button, col6button, col7button, col8button, eraserbutton;
Dimension P_A = new Dimension(500,100);
public paintprog()
{
super("Paint V1");
ImageIcon sqln = new ImageIcon("sqln.gif");
ImageIcon sqfl = new ImageIcon("sqfl.gif");
ImageIcon crln = new ImageIcon("crln.gif");
ImageIcon crfl = new ImageIcon("crfl.gif");
ImageIcon hxln = new ImageIcon("hxln.gif");
ImageIcon hxfl = new ImageIcon("hxfl.gif");
ImageIcon line = new ImageIcon("line.gif");
ImageIcon dash = new ImageIcon("dash.gif");
ImageIcon col1 = new ImageIcon("col1.gif");
ImageIcon col2 = new ImageIcon("col2.gif");
ImageIcon col3 = new ImageIcon("col3.gif");
ImageIcon col4 = new ImageIcon("col4.gif");
ImageIcon col5 = new ImageIcon("col5.gif");
ImageIcon col6 = new ImageIcon("col6.gif");
ImageIcon col7 = new ImageIcon("col7.gif");
ImageIcon col8 = new ImageIcon("col8.gif");
sqlnbutton = new JButton(sqln);
sqflbutton = new JButton(sqfl);
crlnbutton = new JButton(crln);
crflbutton = new JButton(crfl);
hxlnbutton = new JButton(hxln);
hxflbutton = new JButton(hxfl);
linebutton = new JButton(line);
dashbutton = new JButton(dash);
col1button = new JButton(col1);
col2button = new JButton(col2);
col3button = new JButton(col3);
col4button = new JButton(col4);
col5button = new JButton(col5);
col6button = new JButton(col6);
col7button = new JButton(col7);
col8button = new JButton(col8);
eraserbutton = new JButton("Eraser");
shape = new JTextField(20);
shape.setText("line");
colour = new JTextField(6);
colour.setText("black");
combine = new JTextField(27);
combine.setText("black line");
JPanel Panel_1 = new JPanel();
Panel_1.setLayout(new GridLayout(4,2));
Panel_1.add(sqlnbutton);
sqlnbutton.addActionListener(this);
Panel_1.add(sqflbutton);
sqflbutton.addActionListener(this);
Panel_1.add(crlnbutton);
crlnbutton.addActionListener(this);
Panel_1.add(crflbutton);
crflbutton.addActionListener(this);
Panel_1.add(hxlnbutton);
hxlnbutton.addActionListener(this);
Panel_1.add(hxflbutton);
hxflbutton.addActionListener(this);
Panel_1.add(linebutton);
linebutton.addActionListener(this);
Panel_1.add(dashbutton);
dashbutton.addActionListener(this);
JPanel Panel_1b = new JPanel();
Panel_1b.setLayout(new GridLayout(3,1));
Panel_1b.add(Panel_1);
Panel_1b.add(eraserbutton);
eraserbutton.addActionListener(this);
Panel_1b.add(combine);
JPanel Panel_2 = new JPanel();
Panel_2.setLayout(new GridLayout(1,1));
JPanel Panel_3 = new JPanel();
Panel_3.setLayout(new GridLayout(2,4));
Panel_3.add(col1button);
col1button.addActionListener(this);
Panel_3.add(col2button);
col2button.addActionListener(this);
Panel_3.add(col3button);
col3button.addActionListener(this);
Panel_3.add(col4button);
col4button.addActionListener(this);
Panel_3.add(col5button);
col5button.addActionListener(this);
Panel_3.add(col6button);
col6button.addActionListener(this);
Panel_3.add(col7button);
col7button.addActionListener(this);
Panel_3.add(col8button);
col8button.addActionListener(this);
JPanel Panel_X = new JPanel();
Panel_X.setLayout(new GridLayout(1,2));
Panel_X.add(Panel_1b);
Panel_X.add(Panel_2);
Container container = getContentPane();
container.setLayout(new GridLayout(2,1));
container.add(Panel_X);
Panel_X.setPreferredSize(new Dimension(120,550));
container.add(Panel_3);
setSize(550,400);
setVisible(true);
}
//=====================================================
public void actionPerformed(ActionEvent event)
{
String shape_temp, col_temp;
shape_temp = shape.getText();
col_temp = colour.getText();
if(event.getSource() == sqlnbutton){
shape_temp = "square outline";
}else if (event.getSource() == sqflbutton){
shape_temp = "filled square";
}else if (event.getSource() == crlnbutton){
shape_temp = "circle outline";
}else if (event.getSource() == crflbutton){
shape_temp = "filled circle";
}else if (event.getSource() == hxlnbutton){
shape_temp = "hexagonal outline";
}else if (event.getSource() == hxflbutton){
shape_temp = "filled hexagonal";
}else if (event.getSource() == linebutton){
shape_temp = "line";
}else if (event.getSource() == dashbutton){
shape_temp = "dashed line";
}else if (event.getSource() == col1button){
col_temp = "black";
}else if (event.getSource() == col2button){
col_temp = "white";
}else if (event.getSource() == col3button){
col_temp = "red";
}else if (event.getSource() == col4button){
col_temp = "blue";
}else if (event.getSource() == col5button){
col_temp = "green";
}else if (event.getSource() == col6button){
col_temp = "yellow";
}else if (event.getSource() == col7button){
col_temp = "purple";
}else if (event.getSource() == col8button){
col_temp = "grey";
}else if (event.getSource() == eraserbutton){
col_temp = "";
shape_temp = "eraser tool";
}
shape.setText(String.valueOf(shape_temp));
colour.setText(String.valueOf(col_temp));
combine.setText(String.valueOf(col_temp)+" "+String.valueOf(shape_temp));
}
//****************************************************************
public static void main(String[] args)
{
paintprog application = new paintprog();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}