修复以下警告的任何方法:javax.swing.JList是原始类型。对泛型类型的引用<;E>;应该参数化

修复以下警告的任何方法:javax.swing.JList是原始类型。对泛型类型的引用<;E>;应该参数化,java,warnings,jlist,Java,Warnings,Jlist,我有一个购物车系统的代码,使用javax.swing.JList总是会引起问题。有没有办法通过改变一些东西来解决这个问题?我应该用另一种方式写吗 这是代码。(我正在使用Dr.Java,是否还应该使用其他编译器?) import javax.swing.*; 导入java.awt.event.*; 导入java.awt.*; 导入java.io.*; 公共类购物车系统扩展JFrame { 私有JPanel sourceListPanel; 私人JPanel shoppingCartPanel; 私

我有一个购物车系统的代码,使用javax.swing.JList总是会引起问题。有没有办法通过改变一些东西来解决这个问题?我应该用另一种方式写吗

这是代码。(我正在使用Dr.Java,是否还应该使用其他编译器?)

import javax.swing.*;
导入java.awt.event.*;
导入java.awt.*;
导入java.io.*;
公共类购物车系统扩展JFrame
{
私有JPanel sourceListPanel;
私人JPanel shoppingCartPanel;
私人JPanel按钮面板;
私有JList源列表;
私人购物车;
私有JScrollPane滚动窗格;
私有JScrollPane滚动窗格2;
私有JButton addButton;
私有JButton removeButton;
私有JButton checkListButton;
私人书籍;
私人双[]价格;
私有字符串[]购物车;
私家车大小;
私人双倍小计=0.0,税,总计;
购物车系统()
{
setTitle(“购物车系统”);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(新的BorderLayout());
图书=新字符串[25];
价格=新的双倍[25];
购物车=新字符串[25];
cartSize=0;
readDataFromFile();
buildSourceListPanel();
buildShoppingCartPanel();
buildButtonsPanel();
添加(sourceListPanel,BorderLayout.WEST);
添加(shoppingCartPanel,BorderLayout.EAST);
添加(按钮面板,边界布局。南);
包装();
setVisible(真);
}
私有void readDataFromFile()
{
试一试{
DataInputStream dis=新的DataInputStream(新文件InputStream(“BookPrices.txt”);
BufferedReader br=新的BufferedReader(新的InputStreamReader(dis));
int i=0;
弦线;
而((line=br.readLine())!=null){
字符串[]arr=line.split(“,”);
图书[i]=arr[0];
price[i++]=Double.parseDouble(arr[1]);
}
br.close();
dis.close();
}
捕获(异常扩展)
{
System.out.println(exp.toString());
}
}
私有void buildSourceListPanel()
{
sourceListPanel=newjpanel();
sourceList=新的JList(书籍);
sourceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
sourceList.setVisibleRowCount(6);
scrollPane=新的JScrollPane(sourceList);
添加(滚动窗格);
}
私有void buildShoppingCartPanel()
{
shoppingCartPanel=new JPanel();
shoppingCart=new JList();
shoppingCart.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
shoppingCart.setVisibleRowCount(6);
scrollPane2=新的JScrollPane(购物车);
shoppingCartPanel.add(滚动窗格2);
}
私有void buildButtonsPanel()
{
buttonsPanel=新的JPanel();
addButton=新的JButton(“添加到购物车”);
removeButton=新的JButton(“从购物车中移除”);
checkListButton=newjbutton(“检查列表”);
按钮面板设置布局(新流程布局(10));
按钮面板添加(添加按钮);
按钮面板。添加(移除按钮);
按钮面板添加(checkListButton);
addButton.addActionListener(newButtonListener());
removeButton.addActionListener(新的ButtonListener());
addActionListener(newButtonListener());
}
私有类ButtonListener实现ActionListener
{
已执行的公共无效行动(行动事件ae)
{
如果(ae.getSource()==addButton)
{               
购物车[cartSize++]=(字符串)sourceList.getSelectedValue();
shoppingCart.setListData(购物车);
小计+=价格[sourceList.getSelectedIndex()];
}
else if(ae.getSource()==removeButton)
{

对于(int i=0;i将
JList
更改为
JList
或您在列表中输入的任何类型

比如说

sourceList = new JList<String>(books)
sourceList=newjlist(书籍)

是。您似乎希望包含
字符串
,因此可以使用
字符串
声明
列表
。类似于

private JList<String> sourceList;
private JList<String> shoppingCart;
私有JList源列表;
私人购物车;
然后,像这样初始化它们

sourceList = new JList<>();
// ...
shoppingCart = new JList<>();
sourceList=new JList();
// ...
shoppingCart=new JList();
,您可以同时声明初始化

private JList<String> sourceList = new JList<>();
private JList<String> shoppingCart = new JList<>();
private JList sourceList=new JList();
私有JList shoppingCart=新JList();
private JList<String> sourceList = new JList<>();
private JList<String> shoppingCart = new JList<>();