I am Trying to write a Java Program that animates 4 arcs to make it look like a moving fan. As of now I have the arcs drawn and Im trying to make buttons for my slow, med, fast and off settings

Im getting the following errors:
DrawArcs.java:6: cannot find symbol
symbol : class JButton
location: class DrawArcs
private JButton jbtOff = new JButton("Off");

DrawArcs.java:27: cannot find symbol
symbol : class ActionListener
location: class DrawArcs
jbtSlow.addActionListener(new ActionListener(){

Im getting a few more but listing them would be kinda redundant as they refer to the other lines i wrote to create the buttons and action listeners. I figured that If we could solve the first ones the others probably have the same issue.

Any help would be greatly appreciated

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;

public class DrawArcs extends JFrame {
   private JButton jbtOff = new JButton("Off");
	private JButton jbtSlow = new JButton("Slow");
	private JButton jbtMed = new JButton("Med");
	private JButton jbtFast = new JButton("Fast");


	public DrawArcs() {
		JPanel arcsPanel = new JPanel();
		setTitle("DrawArcs");
		arcsPanel.add(jbtOff);
		arcsPanel.add(jbtSlow);
		arcsPanel.add(jbtMed);
		arcsPanel.add(jbtFast);
		
		this.add(arcsPanel, BBorderLayout.SOUTH);	
		
		jbtOff.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
			}
		});
		
			jbtSlow.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
			}
		});
		
			jbtMed.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
			}
		});
		
			jbtFast.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
			}
		});
		
	}
		//Main Method
		public static void main(String[]args){
		DrawArcs frame = new DrawArcs();
		frame.setSize(250, 300);
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
		
	}	
}

		//Draw Arcs On Panel
		class ArcsPanel extends JPanel {
			protected void paintComponent(Graphics g) {
				super.paintComponent(g);
				
				int xCenter = getWidth() /2;
				int yCenter = getHeight() /2;
				int radius = (int)(Math.min(getWidth(),getHeight())*0.4);
				
				int x = xCenter - radius;
				int y = yCenter - radius;
				
				g.fillArc(x, y, 2*radius, 2*radius, 0, 30);
				g.fillArc(x, y, 2*radius, 2*radius, 90, 30);
				g.fillArc(x, y, 2*radius, 2*radius, 180, 30);
				g.fillArc(x, y, 2*radius, 2*radius, 270, 30);
				
				}
		}

Dani AI

Generated

Good call from and — a Java compiler error like "cannot find symbol: class JButton" almost always means the compiler does not see the Swing/AWT types (missing imports) or there is a simple typo. Beyond adding the correct imports, a few further points will prevent follow‑up issues and make the fan animation easier to implement and control.

Use a Swing timer for the rotation instead of spawning threads. A single javax.swing.Timer drives repaint on the Event Dispatch Thread (EDT) and makes changing speed trivial (stop the timer for Off, setDelay for Slow/Med/Fast). Example pattern:

int delay = 100; // ms for medium
Timer timer = new Timer(delay, e -> {
  angle = (angle + 10) % 360;
  arcsPanel.repaint();
});
timer.start();

Build the GUI on the EDT (SwingUtilities.invokeLater), add components before showing the frame, and prefer pack() with preferred sizes rather than forcing setSize. Watch for small typos (your code showed BBorderLayout.SOUTH — that will compile error as much as a missing import). Also consider making the drawing panel an inner class so it can access rotation state and call repaint() directly.

Quick checklist for similar compile/runtime problems:

  • Verify imports (or import javax.swing.*; import java.awt.*; import java.awt.event.*; while learning).
  • Fix typos in constants and class names (BorderLayout, ActionEvent, etc.).
  • Ensure GUI creation runs on the EDT (see Oracle Swing concurrency tutorial).
  • Use javax.swing.Timer for animation to avoid sync issues (see Timer API).

Further reading: Swing concurrency guide (https://docs.oracle.com/javase/tutorial/uiswing/concurrency/) and the Timer API (https://docs.oracle.com/javase/8/docs/api/javax/swing/Timer.html). These explain why the EDT and Swing Timer are the recommended approach for animations.

Recommended Answers

All 3 Replies

you need to import the classes that the compiler isn't finding. Right not you're only importing 3 classes.

Hi there, am only learning java, but I notice you have not imported the libraries, java.awt.event. I thought this was where the refrence to the action listner was held. If not please can you tell me how you got round it.

Hi there, am only learning java, but I notice you have not imported the libraries, java.awt.event. I thought this was where the refrence to the action listner was held. If not please can you tell me how you got round it.

That Fixed one of them... I completely Restructured how I was adding
the buttons and fixed the other problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.