This issue I'm having is trying to allow user to choose from the GUI Combobox drop down #1 box (Choose Oval or Rectangle), #2 box (Filled or Hollow), #3 box (choose a color: Black, Blue, Yellow or Grey). Textfield #1 user can enter the Height, TextField #2 user can enter the Width, Textfield #3 user can enter x-coordinate and TextField #4 user can enter the y-coordinate. Draw button to call the paintComponent method to all the users to choose what they want to make, either Oval or Rectangle so it can be displayed on the Panel.
public class Drawing extends JPanel{
public int currentShape;
public void paintComponent(Graphics g) {
super.paintComponent(g);
int x1 = 0;
int y1 = 0;
g.drawRect(x1, y1, getWidth(), getHeight());
g.getColor();
g.fillRect(getX(), getY(), getWidth(), getHeight());
//g.drawOval(x, y, width, height);
g.getColor();
g.fillOval(getX(), getY(), getWidth(), getHeight());
}
public Dimension getPreferredSize() {
return new Dimension(200, 200);
}
public void drawShape(int currentShape) throws OutsideBounds {
}
}
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.TitledBorder;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JPanel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Project3 {
private JFrame frame;
private JTextField widthTextField;
private JTextField heightTextField;
private JTextField xCoordinateTextField;
private JTextField yCoordinateTextField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Project3 window = new Project3();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Project3() {
initialize();
}
/**
* Initialize the contents of the frame
*/
private void initialize() {
frame = new JFrame();
frame.setTitle("Geometric Drawing");
frame.setBounds(100, 100, 536, 373);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel lblShapeType = new JLabel("Shape Type");
JLabel lblFillType = new JLabel("Fill Type");
JLabel lblColor = new JLabel("Color");
JLabel lblWidth = new JLabel("Width");
JLabel lblHeight = new JLabel("Height");
JLabel lblXCoordinate = new JLabel("x coordinate");
JLabel lblYCoordinate = new JLabel("y coordinate");
//String[] shapeString = { "Oval", "Rectangle"};
JComboBox<String> shapeTypeComboBox = new JComboBox<String>();
//Drawing oval = (Drawing) shapeTypeComboBox.getSelectedItem();
shapeTypeComboBox.addItem("Oval");
shapeTypeComboBox.addItem("Rectangle");
JComboBox<String> fillTypeComboBox = new JComboBox<String>();
fillTypeComboBox.addItem("Solid");
fillTypeComboBox.addItem("Hollow");
JComboBox<String> colorComboBox = new JComboBox<String>();
colorComboBox.addItem("Black");
colorComboBox.addItem("Red");
colorComboBox.addItem("Orange");
colorComboBox.addItem("Yellow");
colorComboBox.addItem("Green");
colorComboBox.addItem("Blue");
colorComboBox.addItem("Magenta");
widthTextField = new JTextField();
widthTextField.setColumns(10);
heightTextField = new JTextField();
heightTextField.setColumns(10);
xCoordinateTextField = new JTextField();
xCoordinateTextField.setColumns(10);
yCoordinateTextField = new JTextField();
yCoordinateTextField.setColumns(10);
JPanel drawPanel = new JPanel();
TitledBorder titled = new TitledBorder("Shape Drawing");
drawPanel.setBorder(titled);
JButton btnDraw = new JButton("Draw");
btnDraw.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});