I connect my dosen.java with my Test5.java, I trying to make panel for Teacher to insert our score. but I make it simple like if teacher want to insert score he just need to find the the class and the subject come out from mapel combobox and insert the grade on the textfield in the bottom. when I put combobox in there I got error like raw type combobox and then my jtable got problem too.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.table.*;
import java.util.*;
import javax.swing.DefaultComboBoxModel;
public class dosen{
JPanel panel_dosen, panel_combo, panel_input;
JTable table;
JLabel label_input,label_input2;
JTextField tf_input,tf_input2;
JButton Insert;
JComboBox<String> classs, mapel; //first Problem
ResultSet rs;
JScrollPane scroll;
Connection conn = null;
Statement stmt = null;
String sql;
public dosen(){
table();
dataInsert();
panel_dosen = new JPanel();
panel_dosen.setLayout(new BorderLayout());
panel_dosen.add(panel_combo, BorderLayout.NORTH);
panel_dosen.add(scroll, BorderLayout.CENTER);
panel_dosen.add(panel_input, BorderLayout.SOUTH);
}
public void panelCombo(){ //combobox panel
panel_combo = new JPanel();
DefaultComboBoxModel classes = new DefaultComboBoxModel(new String[]{"Information System", "Hospitality", "Law", "Management", "Accounting"});
classs = new JComboBox(classes);
mapel = new JComboBox();
classs.addActionListener (new ActionListener () {
public void actionPerformed(ActionEvent e) {
if ("Information System".equals(classs.getSelectedItem())){
DefaultComboBoxModel ISsub = new DefaultComboBoxModel(new String[]{"Statistic and Probability", "Operating System", "Management Information System", "Inggris-2", "Object Oriented Programming"});
mapel.setModel(ISsub);
} else {
DefaultComboBoxModel Hossub = new DefaultComboBoxModel(new String[]{"Statistic and Probability", "Operating System", "Management Information System", "Inggris-2", "Object Oriented Programming1"});
mapel.setModel(Hossub);
}
}
});
classs.setSelectedIndex(0);
mapel.setSelectedIndex(0);
panel_combo.add(classs);
panel_combo.add(mapel);
}
public void table(){//i dont put panel on table because i dont think it needed
table = new JTable();
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setFillsViewportHeight(true);
scroll = new JScrollPane(table);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
DefaultTableModel model = new DefaultTableModel();
String[] columnNames= {"NIM","Grade","Class"};
model.setColumnIdentifiers(columnNames);
table.setModel(model);
String Classes = "";
String Grade = "";
String NIM = "";
String url = "jdbc:mysql://localhost/kampus";
String username = "root";
String password = "abc";
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url, username, password);
sql = "select NIM, Grade, Class from nilai where Mapel = '"+ mapel.getSelectedItem() +"' AND Major = '" + classs.getSelectedItem() +"'";
PreparedStatement ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
NIM = rs.getString("NIM");
Classes = rs.getString("Kelas");
Grade = rs.getString("Nilai");
model.addRow(new Object[]{NIM, Grade, Classes});
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
public void dataInsert(){
panel_input = new JPanel();
panel_input.setLayout(new GridBagLayout());
label_input = new JLabel("NIM : ");
label_input2 = new JLabel("Nilai : ");
tf_input = new JTextField(15);
tf_input2 = new JTextField(15);
Insert = new JButton("Insert");
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.LINE_START;
panel_input.add(label_input, gbc);
gbc.gridy++;
panel_input.add(label_input2, gbc);
gbc.gridy = 0;
gbc.gridx++;
gbc.anchor = GridBagConstraints.LINE_END;
panel_input.add(tf_input, gbc);
gbc.gridy++;
panel_input.add(tf_input2, gbc);
gbc.gridy++;
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridwidth = GridBagConstraints.REMAINDER;
panel_input.add(Insert, gbc);
}
}
dosen.java:31: warning: [rawtypes] found raw type: DefaultComboBoxModel
DefaultComboBoxModel classes = new DefaultComboBoxModel(new String[]{"Information System", "Hospitality", "Law", "Management", "Accounting"});
^
missing type arguments for generic class DefaultComboBoxModel<E>
where E is a type-variable:
E extends Object declared in class DefaultComboBoxModel
String Class = "";
Change this variable's name. Because of this line
Class.forName("com.mysql.jdbc.Driver");
forName
method calling from a String
instance. Bu there is not a method named forName
in String
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.