Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

awt classes

 
Sartaj Syed
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having some problem with the following code. Please help

import java.awt.*;
import java.awt.AWTEvent;
public class TS1 extends Frame {
TS1(){
super("Project Development Coordination System");
setSize(500,500);
setLayout(new BorderLayout());

//Build and add 1st Panel of TS1
Panel p1 = new Panel(new BorderLayout());
TextField Title = new TextField();
Title.setFont(new Font("Sansserif", Font.BOLD, 48));
Title.setText("HORNSONIC");
Title.setEditable(false);
TextField Name = new TextField();
Name.setFont(new Font("Sansserif", Font.BOLD, 30));
Name.setText("Hera International, Inc.");
Name.setEditable(false);
p1.add(Title, BorderLayout.NORTH);
p1.add(Name, BorderLayout.CENTER);
add(p1, BorderLayout.NORTH);
//Build and add 2nd Panel
Panel PDCS = new Panel();
TextField pdcs = new TextField();
pdcs.setFont(new Font("Sanserif", Font.BOLD, 22));
pdcs.setText("Project Development Coordination System");
pdcs.setEditable(false);
PDCS.add(pdcs);
Button input = new Button("INPUT");
input.addActionListener(new In ());
PDCS.add(input);
Button feedback = new Button("FEEDBACK");
feedback.addActionListener(new Feed());
PDCS.add(feedback);
add(PDCS, BorderLayout.CENTER);

//class In
class In implements ActionListener{
public void actionPerformed(ActionEvent ae){
System.out.println("In");}}
// class Feed
class Feed implements ActionListener{
public void actionPerformed(ActionEvent AE){
System.out.println("Feed");}}
The compilation errors I am gettin says cannot resolve symbol ActionListener. and ActionEvent
 
Ian Darwin
author
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sartaj Syed:
I am having some problem with the following code. Please help

import java.awt.*;
import java.awt.AWTEvent;
public class TS1 extends Frame {
...
}
The compilation errors I am getting says cannot resolve symbol ActionListener. and ActionEvent

You need to import java.awt.event.*. This is not the same as the import of java.awt.AWTEvent (which, btw, is redundant since you already imported java.awt.*). So change that second import to
import java.awt.event.*;
and your code should compile (if that's the only compile error you were getting).
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ian,
Haven't seen you around lately. Just had your book out yesterday for someone at work .
 
Sartaj Syed
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ian that solved my problem as far as compilation goes.
I need some more help . This particular code was like the main screen of my application . I want to use one button to open up another screen called Input screen and the second button to open up a feedback screen. I have the code for Input in an Input class ( in the same file) and the code(everything compiles). for Feedback in a feedback class. How do I do this?
As of now the main screen has these buttons but clicking them the action performed method does just a print statement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic