Hello guys, I have built another small GUI:
Even before knowing whether the layout of the application I have built is right, I am facing another big problem. At compiling time I get the following error:
Note: Dropdown.java uses unchecked or unsafe operation
Note: Recompile with -Xlint:unchecked for details.
I had a look online and it seems that it has something to do with arrays but for the life of me I don't seem to be able to find the error. ANy idea?
Once that solved we can have a look at any possible error in the layout :-)
Here is the code:
/*Dropdown.java
ex 14.10 p 662.
-create 2 jPanels, one for tick boxes and one for buttons. The dropdown needs no panel.
Border layout will position the elements in the middle
*/
import java.awt.FlowLayout;//arrange the components inside the panels
import java.awt.BorderLayout;//arrange thepanels containing the components
import javax.swing.JFrame;//provides basic window feature
import javax.swing.JPanel;//for the panels
import javax.swing.JButton;//for the buttons
import javax.swing.JCheckBox;//for the chekboxes
import javax.swing.JComboBox;//for dropdown
public class Dropdown extends JFrame{
private JCheckBox background;
private JCheckBox foreground;
private JPanel comboBoxPanel; //panel holding the checkboxes
private JPanel checkboxesPanel; //panel holding the checkboxes
private JPanel buttonsPanel;//panel holding the buttons
private JComboBox dropdown; //combobox
private BorderLayout JframeLayout;//layout manager for checkboxes panel
private FlowLayout comboBoxLayout;//layout manager for combo box
private FlowLayout checkboxesLayout;//layout manager for checkboxes
private FlowLayout buttonsLayout;//layout manager for buttons
private String[] values;//holds the string values of the combo box
private JButton okButton;//holds the ok button
private JButton cancelButton;//holds the cancel button
public Dropdown(){
super("Colour Select");
JframeLayout = new BorderLayout( 0, 5);
setLayout( JframeLayout );//set layout of jframe
//combo box controller
comboBoxPanel = new JPanel();
comboBoxLayout = new FlowLayout();
String[] values = {"Red", "Yellow", "Blue", "Magenta", "Green", "Orange", "Pink"};
dropdown = new JComboBox( values );
dropdown.setMaximumRowCount( 3 );//set maximum visible elements
comboBoxPanel.setLayout( comboBoxLayout );//set the flow layout for the jpanel
comboBoxPanel.add( dropdown );//add combo box to Jpanel
//do I need to set the size of the combo box?
// checkboxes controllers
checkboxesPanel = new JPanel();
checkboxesLayout = new FlowLayout();
background = new JCheckBox( "Background" );
foreground = new JCheckBox( "Foreground" );
checkboxesPanel.setLayout( checkboxesLayout );//set layout of controllers in Jpanel
checkboxesPanel.add( background );//add checkbox to JPanel
checkboxesPanel.add( foreground );//add checkbox to JPanel
//buttons controllers
buttonsPanel = new JPanel();
buttonsLayout = new FlowLayout();
okButton = new JButton( "OK" );
cancelButton = new JButton( "Cancel" );
buttonsPanel.setLayout( buttonsLayout );//set layout of controllers in jpanel
buttonsPanel.add( okButton );//add button to jpanel
buttonsPanel.add( cancelButton );//add button to jpanel
//add panels to JFrame
add( comboBoxPanel, BorderLayout.PAGE_START );//add the combobox panel at the top of the JFrame
add( checkboxesPanel, BorderLayout.CENTER );// panel at teh centre of the page
add( buttonsPanel, BorderLayout.CENTER );//add panel at teh bottom
}//end of constructor
}//end of Dropdown class
And the test class
/*
testing class Dropdown.
DropdownTest.java
*/
import javax.swing.JFrame;
import java.awt.Dimension;//specify the dimensions
public class DropdownTest{
public static void main( String[] args ){
Dropdown dropdownTest = new Dropdown();
dropdownTest.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
dropdownTest.setVisible( true );
Dimension minimumSize = new Dimension( 400, 200 );//specify dimensions
dropdownTest.setMinimumSize( minimumSize );//set dimensions
dropdownTest.setResizable( false );
dropdownTest.pack();
}//end of main
}//end of class