获取编译器错误:警告:未检查对作为原始类型JComboBox成员的addItem(E)的调用



我在Netbeans IDE 8.2中做一个商店,由于这个错误,我无法编译。我试图通过添加到JComboBox来修复它,但它并没有解决我的问题。此应用程序的Web版本运行良好,但我无法编译它。当使用Xlint:Unchecked运行时,这是一个警告:[Unchecked]Unchecked调用addItem(E(作为原始类型JComboBox的成员list.addItem;其中E是类型变量:E扩展类JComboBox中声明的Object1个警告

package warstwa_klienta_desktop;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.BoxLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
public class Produkty_form extends JPanel  {
private JTable tabela_produktow;    
MyTableModel model;         
JComboBox<String> lista_produktow;      
public void init() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
model = new MyTableModel(); 
tabela_produktow = new JTable(model);   
table_content();

tabela_produktow.setPreferredScrollableViewportSize(new Dimension(800, 100));
tabela_produktow.setFillsViewportHeight(true);
tabela_produktow.getSelectionModel().addListSelectionListener(new RowListener());                                        
add(new JScrollPane(tabela_produktow));                      
JLabel lprodukty = new JLabel("Produkty");
add(lprodukty);
JComboBox<String>lista_produktow = new JComboBox<>();
add(lista_produktow);
}
void table_content() {              
ArrayList<ArrayList<String>> produkty = GUI_main.getFacade().items();
model.setData(produkty);
tabela_produktow.repaint();
}
private void list_content(ArrayList<ArrayList<String>> col, JComboBox list)  {

ArrayList<String> s;                
list.removeAllItems();
Iterator<ArrayList<String>> iterator = col.iterator();
while (iterator.hasNext()) {
s = iterator.next();
list.addItem(s);
}
}
void print_produkty() {     
ArrayList<ArrayList<String>> help3 = GUI_main.getFacade().items();             
if (help3 != null) {
list_content(help3, lista_produktow);                     
}
}
private class RowListener implements ListSelectionListener {        
@Override
public void valueChanged(ListSelectionEvent event) {        
if (event.getValueIsAdjusting()) {          
return;
}
print_produkty();       
}
}
class MyTableModel extends AbstractTableModel { 
private final String[] columnNames = {"Id produktu", "Nazwa", "Cena", 
"Promocja", "Data", "Cena brutto"};
private ArrayList<ArrayList<String>> data;  
public void setData(ArrayList<ArrayList<String>> val) {             
data = val;
}
@Override
public int getColumnCount() {
return columnNames.length;              
}
@Override
public int getRowCount() {
return data.size();                 
}
@Override
public String getColumnName(int col) {
return columnNames[col];
}
@Override
public Object getValueAt(int row, int col) {
return data.get(row).get(col);      
}

}

}

GUI_main看起来像这个

package warstwa_klienta_desktop;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.ejb.EJB;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import warstwa_biznesowa_ejb.Fasada_warstwy_biznesowej_ejbRemote;
public class GUI_main implements ActionListener {
@EJB
private static Fasada_warstwy_biznesowej_ejbRemote fasada;
static JPanel cards;    
static CardLayout cl;   

static Pusty_form card0 = new Pusty_form();     
static Produkt_form card1 = new Produkt_form(); 
static Produkty_form card2 = new Produkty_form();
final static String PUSTY = "Pusty";
final static String PRODUKT = "Produkt form";
final static String PRODUKTY = "Produkty form";


static public Fasada_warstwy_biznesowej_ejbRemote getFacade() {
return fasada;
}
public JMenuBar createMenuBar() {
JMenuBar menuBar;
JMenu menu, submenu;
JMenuItem menuItem;
menuBar = new JMenuBar();           
menu = new JMenu("A Menu");
menu.setMnemonic(KeyEvent.VK_A);            
menuBar.add(menu);              
menuItem = new JMenuItem(PRODUKT, KeyEvent.VK_P);   
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_1, ActionEvent.ALT_MASK));  
menuItem.addActionListener(this);           
menu.add(menuItem);             
menuItem = new JMenuItem(PRODUKTY);
menuItem.setMnemonic(KeyEvent.VK_R);  
menuItem.addActionListener(this);       
menu.add(menuItem);             
menuItem = new JMenuItem(PUSTY);
menuItem.setMnemonic(KeyEvent.VK_U);    
menuItem.addActionListener(this);       
menu.add(menuItem);         
menu.addSeparator();
submenu = new JMenu("A submenu");       
submenu.setMnemonic(KeyEvent.VK_A); 
menuItem = new JMenuItem(PUSTY);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_2, ActionEvent.ALT_MASK));  
menuItem.addActionListener(this);       
submenu.add(menuItem);      
menuItem = new JMenuItem(PUSTY);
menuItem.setMnemonic(KeyEvent.VK_S);    
menuItem.addActionListener(this);       
submenu.add(menuItem);      
menu.add(submenu);             
menu = new JMenu("Inne Menu");          
menu.setMnemonic(KeyEvent.VK_I);        
menuBar.add(menu);          
return menuBar;         
}
public Container createContentPane() {

card1.init();
card2.init();
cards = new JPanel(new CardLayout());
cards.add(card0, PUSTY);        
cards.add(card1, PRODUKT);      
cards.add(card2, PRODUKTY); 
JPanel p1 = new JPanel();       
p1.add(cards, BorderLayout.CENTER); 
return p1;          
}
public static void updateProdukty_form() {
card2.table_content();      

cl.show(cards, PRODUKTY);   
}
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem source = (JMenuItem) (e.getSource());     
//   CardLayout cl = (CardLayout) (cards.getLayout());
cl = (CardLayout) (cards.getLayout());
switch (source.getText()) {
case PRODUKT:
cl.show(cards, PRODUKT);    
break;
case PRODUKTY:
updateProdukty_form();  
break;
case PUSTY:
cl.show(cards, PUSTY);      
break;
default:
break;
}
}
private static void createAndShowGUI() {        
JFrame frame = new JFrame("MenuDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(900, 400);
GUI_main demo = new GUI_main();
frame.setJMenuBar(demo.createMenuBar());    
frame.setContentPane(demo.createContentPane());
frame.setVisible(true);         
}
public static void main(String[] args) {

java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
}
}

相关内容

  • 没有找到相关文章

最新更新