ISYS 303 - GUI Flashcards
how to set things visible/invisible
.setVisible(boolean: true or false);
EX: GreenPanel.setVisible(true);
set cursor in specific place (i.e textbox)
nameoftextbox.requestFocus();
EX: txtYourName.requestFocus();
convert double to a string
or anything to string
String.valueOf(NameofVariable.getSelectedItem());
String.valueOf(cmbIS100.getSelectedItem()),
convert string to a double
(or anything to double)
or integer
Double.parseDouble(NameofVariable.getText())
Integer.parseInt(NameofVariable.getText())
Double.parseDouble(txtIS100.getText())
DecimalFormat
DecimalFormat oDF = new DecimalFormat(#.00); String sToHoldDecimal = oDF.format(whatyouwanttoformat)
GPALabel.setText(oDF.format(dFinGPA))
set Textbox/Label
NameOfTxtBox/Lbl.setText(“anythinghere”);
set combo box
NameOfCmb.setSelectedIndex(#);
**the # starts with 0, and ends with as many options as your put
set jDialog form Visible/Not Visible
private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false);
}
This statement tells the form that when the Close button is clicked it then the form object will change its visibility to false (thus hiding it)
String sSQL
This variable will hold the SQL statement. It is not really needed but I am showing that you could dynamically build a SQL statement and store it to a variable and then use that variable within your program to access the data
try{
All of the source code to access the database is protected within a try statement. That way if something goes wrong, Java can try to recover as needed.
String driver = “net.ucanaccess.jdbc.UcanaccessDriver”;
Class.forName(driver);
The Class.forName(driver) statement specifies a specific driver that Java will use within the program. This statement indicates that Java will be using the UcanaccessDriver within the source code that follows
Connection con = DriverManager.getConnection(“jdbc:ucanaccess://C:/Test/GoldStarHR.accdb”);
The Connection object informs Java which database file to use and how to access it. The jdbc (which stands for Java database connectivity) uses the ucanaccess driver
Statement stmt = con.createStatement();
The Statement object connects the Connection object with a statement that will be executed and
specified later. It will be the actual SQL statement
sSQL = “Select SSN, Last_Name, First_Name, Hire_Date FROM Employee”;
This is the string variable set up earlier to hold the SQL statement
ResultSet rs = stmt.executeQuery(sSQL);
The ResultSet object contains the data returned from the Statement object attached to the Connection object using the SQL statement in the sSQL variable. So in essence, this runs the SQL statement and returns all of the records from the Employee table showing the SSN, Last_Name, First_Name, and Hire_Date columns