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
DefaultTableModel model = (DefaultTableModel)tblEmployee.getModel();
The DefaultTableModel object indicates the storage space for the data to be used. Remember that the model represents the data. This statements says to create a model object and base it up on the tblEmployee JTable object on the form
model.setRowCount(0);
This statement says to highlight the first row of data
if (rs != null) while ( rs.next() ){ model.addRow(new Object[]{ rs.getString("SSN"), rs.getString("Last_Name"), rs.getString("First_Name"), rs.getString("Hire_Date") }); }
These statements says If there is a row in the result set called rs While there is a row of data Add a new row of data to the new model object using the columns specified IOW, this will check to see if there is data and as long as there IS data, extract the SSN, Last_Name,First_Name, and Hire_Date from the table and add it to the model for the JTable object.
stmt. close();
con. close();
Then we close the resources we created
char charAt
char charAt = sNameTogether.charAt(iCount); //finds the letter in the names from the counter
String valueOf = String.valueOf(charAt); //converts the found letter to a string
Combo boxes
cmbIS100.setSelectedIndex(0); //resets the combo box to "A"
cmbIS100.getSelectedItem())
Text boxes
txtIS100.getText()
Checkboxes
cbHTAdv.setSelected(false);
cbHTAdv.isSelected()
ListBoxes
confTeamList.getModel().getSize()
confTeamList.getModel().getElementAt(iCounter).toString()