Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

use Unchecked or unsafe operations: recompile with -Xlint

807603Feb 17 2008 — edited Feb 17 2008
hi all..
I'm trying to create a GUI to select the necessary port to open. I got this code from JAVA cookbook:
I'm using windows XP and JDK 1.6..
import java.io.*;
import javax.comm.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class PortChooser extends JDialog implements ItemListener {

 HashMap map = new HashMap();

 String selectedPortName;

 CommPortIdentifier selectedPortIdentifier;

JComboBox serialPortsChoice;

 JComboBox parallelPortsChoice;

 JComboBox other;

 SerialPort ttya;

 JLabel choice;



protected final int PAD = 5;


public void itemStateChanged(ItemEvent e) {

selectedPortName = (String)((JComboBox)e.getSource()).getSelectedItem();

selectedPortIdentifier = (CommPortIdentifier)map.get(selectedPortName);

choice.setText(selectedPortName);
}

public String getSelectedName() {
return selectedPortName;
}

public CommPortIdentifier getSelectedIdentifier() {
return selectedPortIdentifier;
}

public static void main(String[] ap) {
PortChooser c = new PortChooser(null);
c.setVisible(true);// blocking wait
System.out.println("You chose " + c.getSelectedName() +" (known by " + c.getSelectedIdentifier() + ").");
System.exit(0);
}

public PortChooser(JFrame parent) {
super(parent, "Port Chooser", true);
makeGUI();
populate();
finishGUI();
}

protected void makeGUI() {

Container cp = getContentPane();

JPanel centerPanel = new JPanel();
cp.add(BorderLayout.CENTER, centerPanel);

centerPanel.setLayout(new GridLayout(0,2, PAD, PAD));

centerPanel.add(new JLabel("Serial Ports", JLabel.RIGHT));
serialPortsChoice = new JComboBox();
centerPanel.add(serialPortsChoice);
serialPortsChoice.setEnabled(false);

centerPanel.add(new JLabel("Parallel Ports", JLabel.RIGHT));
parallelPortsChoice = new JComboBox();
centerPanel.add(parallelPortsChoice);
parallelPortsChoice.setEnabled(false);

centerPanel.add(new JLabel("Unknown Ports", JLabel.RIGHT));
other = new JComboBox();
centerPanel.add(other);
other.setEnabled(false);

centerPanel.add(new JLabel("Your choice:", JLabel.RIGHT));
centerPanel.add(choice = new JLabel());
JButton okButton;
cp.add(BorderLayout.SOUTH, okButton = new JButton("OK"));
okButton.addActionListener(new ActionListener() {
	public void actionPerformed(ActionEvent e) {
		PortChooser.this.dispose();
	}
	});
		}
/** Populate the ComboBoxes by asking the Java Communications API
* what ports it has. Since the initial information comes from
* a Properties file, it may not exactly reflect your hardware.
*/
protected void populate() {

Enumeration pList = CommPortIdentifier.getPortIdentifiers();

while (pList.hasMoreElements()) {
CommPortIdentifier cpi = (CommPortIdentifier)pList.nextElement();

// System.out.println("Port " + cpi.getName());
map.put(cpi.getName(), cpi);
if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) {
serialPortsChoice.setEnabled(true);
serialPortsChoice.addItem(cpi.getName());
} 
else if (cpi.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
parallelPortsChoice.setEnabled(true);
parallelPortsChoice.addItem(cpi.getName());
} 
else {
other.setEnabled(true);
other.addItem(cpi.getName());
}
}
serialPortsChoice.setSelectedIndex(-1);
parallelPortsChoice.setSelectedIndex(-1);
}
protected void finishGUI() {
serialPortsChoice.addItemListener(this);
parallelPortsChoice.addItemListener(this);
other.addItemListener(this);
pack();
//addWindowListener(new WindowCloser(this, true));
}}
When i compile this it says PortChooser.java uses unchecked or unsafe operation
recompile with -Xlint(any one know what this is?)
Is it the JDK version i'm using ? First i thought it's a security issue.As in windows is not letting me access the serial ports.
I checked with device manager.My serial ports are open. Ichanged my BIOS settings as well..
(I read inputs from parallel port.But i dont use the comm api for that)
I have installed the rxtx gnu.io package as well..
Tried import gnu.io.* instead of javax.comm.*; still the same compilatiion error!!!
Thanks in advance
goodnews:-(
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 16 2008
Added on Feb 17 2008
4 comments
1,307 views