Frage

Help! It says it can't find the symbol of the following:

 * c.setBackground(Color.Gray);         

 * Admin.setForeground(Color.White);      

 * AdminPass.setForeground(Color.White);      

Ok, so here's the program.


import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

public class Login extends JFrame implements ActionListener
{

    JLabel Admin = new JLabel ("Username: ");
    JTextField txtAdmin = new JTextField(20);
    JLabel AdminPass = new JLabel ("Password: ");
    JPasswordField txtPass = new JPasswordField(20);
    JLabel RemarksLabel = new JLabel();
    JButton OK = new JButton ("OK");
    JButton Cancel = new JButton ("Cancel");

    Container c = getContentPane();

    public Login()
    {
        c.setLayout (null);
        c.setBackground(Color.Gray);
        c.add(Admin);
        Admin.setForeground(Color.White);
        c.add(txtAdmin);
        c.add(AdminPass);
        AdminPass.setForeground(Color.White);
        c.add(txtPass);
        c.add(RemarksLabel);
        c.add(OK);
        c.add(Cancel);

        Admin.setBounds(10,20,80,20);
        txtAdmin.setBounds(80,20,100,20);
        AdminPass.setBounds(10,45,80,20);
        txtPass.setBounds(80,45,100,20);
        OK.setBounds(70,70,55,20);
        Cancel.setBounds(125,70,55,20);
        txtPass.addActionListener(this);
        OK.addActionListener(this);
        Cancel.addActionListener(this);


    }
}
War es hilfreich?

Lösung

I tried to compile it and I think the reason is, that you have to use Color.GRAY instead of Color.Gray ...

Andere Tipps

The issue is with the character case. You cant use a mix of lower and upper case like Color.White. It should be either Color.white (all in lowercase) or Color.WHITE (all in uppercase)

However if you are using all uppercase like Color.WHITE and still showing error you should probably check your java compiler version or compliance level.

The uppercase Color.WHITE was added since java 1.4 if you are using a prior version it wont recognise. use Color.white.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top