Question
Hi I need help with this program I am trying to make for a Java Programming class. I was given code for a few programs
Hi I need help with this program I am trying to make for a Java Programming class. I was given code for a few programs that already work, but wasn't formatted properly. I was tasked with making the code look more "readable" in addition to making sure it works after cleaning it up. But I am having an issue with this one program. It is a digital clock that is supposed to display whatever time my computer says, but in a new window.
Hereis the code I was given, after cleaning it up
import java.awt.Font; import java.awt.Color; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.Timer; import javax.swing.SwingConstants; import java.util.*; import java.text.*;
public class DigitalClock { public static void main(String[]arguments) { Clock Label; date Lable = new ClockLabel("date"); Clock Label; time Lable = new ClockLabel("time"); Clock Label; day Lable = new ClockLabel("day"); JFrame.setDefaultLookAndFeelDecorated(true); JFramef=newJFrame("DigitalClock"); f.setSize(300,150); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(newGridLayout(3,1));f.add(dateLable); f.add(timeLable);f.add(dayLable); f.getContentPane().setBackground(Color.black); f.setVisible(true); } } class ClockLabel extends JLabel implements ActionListener { String type; Simple Date; Formats df; public Clock Label(Stringtype) { this.type=type;setForeground(Color.green); switch(type) { case"date":sdf=newSimpleDateFormat("MMMMddyyyy"); setFont(newFont("sans-serif",Font.PLAIN,12)); setHorizontalAlignment(SwingConstants.LEFT); break; case"time":sdf=newSimpleDateFormat("hh:mm:ssa"); setFont(newFont("sans-serif",Font.PLAIN,40)); setHorizontalAlignment(SwingConstants.CENTER); break; case"day":sdf=newSimpleDateFormat("EEEE"); setFont(newFont("sans-serif",Font.PLAIN,16));setHorizontalAlignment(SwingConstants.RIGHT); break;default:sdf=newSimpleDateFormat(); break; Timert=newTimer(1000,this);t.start(); } } public void actionPerformed(Action Eventae) { Dated=newDate(); setText(sdf.format(d)); } }
When I try to compile it, I get an issue in line 48. specifically, the line "public Clock Label(Stringtype)"
when I try to compile it, it shows an arrow after the ")" and says identifier expected. I am wondering if someone could help me troubleshoot this
import java.awt.Font; import java.awt.Color; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.Timer; import javax.swing.SwingConstants; import java.util.*; import java.text.*;
public class DigitalClock { public static void main(String[]arguments) { Clock Label; date Lable = new ClockLabel("date"); Clock Label; time Lable = new ClockLabel("time"); Clock Label; day Lable = new ClockLabel("day"); JFrame.setDefaultLookAndFeelDecorated(true); JFramef=newJFrame("DigitalClock"); f.setSize(300,150); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(newGridLayout(3,1));f.add(dateLable); f.add(timeLable);f.add(dayLable); f.getContentPane().setBackground(Color.black); f.setVisible(true); } } class ClockLabel extends JLabel implements ActionListener { String type; Simple Date; Formats df; public Clock Label(Stringtype) { this.type=type;setForeground(Color.green); switch(type) { case"date":sdf=newSimpleDateFormat("MMMMddyyyy"); setFont(newFont("sans-serif",Font.PLAIN,12)); setHorizontalAlignment(SwingConstants.LEFT); break; case"time":sdf=newSimpleDateFormat("hh:mm:ssa"); setFont(newFont("sans-serif",Font.PLAIN,40)); setHorizontalAlignment(SwingConstants.CENTER); break; case"day":sdf=newSimpleDateFormat("EEEE"); setFont(newFont("sans-serif",Font.PLAIN,16));setHorizontalAlignment(SwingConstants.RIGHT); break;default:sdf=newSimpleDateFormat(); break; Timert=newTimer(1000,this);t.start(); } } public void actionPerformed(Action Eventae) { Dated=newDate(); setText(sdf.format(d)); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started