Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #4875

Scope of a JLabel? Also "unchecked operation"

From "A B" <@bleBaker.uk>
Newsgroups comp.lang.java.gui
Subject Scope of a JLabel? Also "unchecked operation"
Date 2012-01-03 19:02 +0000
Message-ID <4f0350b3$0$2549$da0feed9@news.zen.co.uk> (permalink)
Organization Zen Internet

Show all headers | View raw


I'm quite new to Java, so I expect what I'm asking is fairly basic, but I 
can't find it in my Java book, so I'd be glad if someone could explain very 
simply what's the matter.

1)The program I'm writing is called Vectorine, never mind why.  Lately I get 
this when I compile it: "[...]Vectorine.java uses unchecked or unsafe 
operations.  Recompile with -Xlint: unchecked for details."  It doesn't seem 
to stop it running, though, when I comment out the bit that causes problem 
2).  It didn't do it before I introduced some Swing components.  What is 
this?  Does it matter?

2) The itemStateChanged method can't recognise a perfectly good JTextArea 
that I want it to output to, just keeps saying that there is no variable 
called "display".  Replacing the JTextArea with a JLabel doesn't help, and 
in either case they appear all right.  It's only the method that can't see 
them.  Is this about variable scope?  My Java book isn't very clear about 
that.
This is the program, minus some methods that don't take part in the 
interface.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Vectorine extends JFrame implements ItemListener
{
public Vectorine()
{
super("Vectorine");
setSize(236, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);

// Set up window's initial contents
Container contentArea = getContentPane();
FlowLayout layout = new FlowLayout();
contentArea.setLayout(layout);

Image picture = Toolkit.getDefaultToolkit().getImage("RobotA.gif");
ImageIcon icon = new ImageIcon(picture);
JLabel picLabel = new JLabel(icon);
contentArea.add(picLabel);
JTextField fileslot = new JTextField(20);
contentArea.add(fileslot);
JComboBox types = new JComboBox();
types.addItem("Test");
types.addItemListener(this);
contentArea.add(types);
JTextArea display = new JTextArea("Type here.", 4, 18);
JScrollPane displayPane = new JScrollPane(display, 
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
contentArea.add(displayPane);

setContentPane(contentArea);
}

public void itemStateChanged(ItemEvent event)
{
String choice = event.getItem().toString();
display.setText("Option chosen: "+choice);              // This is where the 
compiler sticks; says it can't find any object called "display".
}

public static void main()
 {
    // show the window
    Vectorine v = new Vectorine();
 }
}

Many thanks,
-- 
A. B.
><>
My e-mail address is zen177395 at  zendotcodotuk, though I don't check that 
account very often.
Post unto others as you would have them post unto you. 

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar


Thread

Scope of a JLabel?  Also "unchecked operation" "A B" <@bleBaker.uk> - 2012-01-03 19:02 +0000
  Re: Scope of a JLabel?  Also "unchecked operation" markspace <-@.> - 2012-01-03 11:05 -0800
  Re: Scope of a JLabel?  Also "unchecked operation" markspace <-@.> - 2012-01-03 11:18 -0800
    Re: Scope of a JLabel?  Also "unchecked operation" "A B" <@bleBaker.uk> - 2012-01-03 21:22 +0000
      Re: Scope of a JLabel?  Also "unchecked operation" markspace <-@.> - 2012-01-03 14:10 -0800
        Re: Scope of a JLabel?  Also "unchecked operation" "A B" <@bleBaker.uk> - 2012-01-04 21:05 +0000
          Re: Scope of a JLabel?  Also "unchecked operation" markspace <-@.> - 2012-01-04 13:10 -0800
          Re: Scope of a JLabel?  Also "unchecked operation" "Gavino" <invalid@invalid.invalid> - 2012-01-05 19:54 +0100
            Re: Scope of a JLabel?  Also "unchecked operation" "A B" <@bleBaker.uk> - 2012-01-12 18:51 +0000
  Re: Scope of a JLabel? Also "unchecked operation" "A B" <@bleBaker.uk> - 2012-01-04 20:58 +0000
    Re: Scope of a JLabel? Also "unchecked operation" "A B" <@bleBaker.uk> - 2012-01-12 18:53 +0000

csiph-web