Latest Oop Code

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

package GUI;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.*;
import javax.swing.*;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Calendar;
import java.text.SimpleDateFormat;

public class FrameOne {


int Hr, Min, Sec;
JFrame frame = new JFrame();
JButton button = new JButton();
JButton HrUpbut = new JButton("+");
JButton MnUpbut = new JButton("+");
JButton SUpbut = new JButton("+");
JButton HrDownbut = new JButton("-");
JButton MnDownbut = new JButton("-");
JButton SDownbut = new JButton("-");
Date date = new Date();
SimpleDateFormat formd = new SimpleDateFormat("MMMM/dd/Y");
SimpleDateFormat formh = new SimpleDateFormat("hh");
SimpleDateFormat formM = new SimpleDateFormat("mm");
SimpleDateFormat forms = new SimpleDateFormat("ss");
SimpleDateFormat formm = new SimpleDateFormat("EEEE");
String a = formd.format(date);
String b = formh.format(date);
String c = formm.format(date);
String d = formM.format(date);
String e = forms.format(date);
JLabel AlarmSetHR = new JLabel();
JLabel AlarmSetMin = new JLabel();
JLabel AlarmSetSec = new JLabel();
JLabel label = new JLabel();
JTextField txtField = new JTextField();
Font newFont = new Font("Arial", Font.BOLD, 35);

FrameOne(){
FrameSwing();
AlarmSetSwing();
HrUpSwing();
MnUpSwing();
SUpSwing();
HrDownSwing();
MnDownSwing();
SDownSwing();
ButtonSwing();
LabelSwing();

public void FrameSwing() {


frame.setSize(1050,700);
frame.setTitle("Alarm Clock - PEJI - CONTRERAS");
frame.getContentPane().setBackground(Color.WHITE);
frame.setLocation(450,180);
frame.setVisible(true);
frame.setResizable(false);
frame.setLayout(null);
frame.add(AlarmSetHR);
frame.add(HrUpbut);
frame.add(MnUpbut);
frame.add(SUpbut);
frame.add(HrDownbut);
frame.add(MnDownbut);
frame.add(SDownbut);
frame.add(button);
frame.add(label);
frame.addWindowListener(new FrameEvent());
}

public void TimeSetter(int h, int m, int s) {


Hr = ((h >=0 && h <=24) ? h:0);
Min = ((m >=0 && h <=60) ? h:0);
Sec = ((s >=0 && h <=60) ? h:0);

public String TimeForm() {


return String.format("%02d:%02d:%02d", Hr,Min,Sec);
}

public void AlarmSetSwing() {


AlarmSetHR.setVisible(true);
AlarmSetHR.setSize(825, 260);
AlarmSetHR.setLocation(100, 240);
AlarmSetHR.setOpaque(true);
AlarmSetHR.setText(TimeForm());
AlarmSetHR.setBackground(Color.BLACK);
AlarmSetHR.setForeground(Color.WHITE);
AlarmSetHR.setHorizontalAlignment(0);
AlarmSetHR.setVerticalAlignment(0);
AlarmSetHR.setFont(new Font("Arial", 1, 175));
}

public void HrUpSwing() {


HrUpbut.setSize(275,40);
HrUpbut.setText("+");
HrUpbut.setLocation(100,200);
HrUpbut.setBackground(Color.WHITE);
HrUpbut.setForeground(Color.BLACK);
HrUpbut.setFont(new Font("Arial", 1, 50));
HrUpbut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Hr++;
if (Hr > 24) {
Hr = 0;
}
AlarmSetHR.setText(TimeForm());
}
});
}

public void MnUpSwing() {


MnUpbut.setSize(275,40);
MnUpbut.setText("+");
MnUpbut.setLocation(375,200);
MnUpbut.setBackground(Color.WHITE);
MnUpbut.setForeground(Color.BLACK);
MnUpbut.setFont(new Font("Arial", 1, 50));
MnUpbut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Min++;
if (Min > 59) {
Min = 0;
}
AlarmSetHR.setText(TimeForm());
}
});

public void SUpSwing() {


SUpbut.setSize(275,40);
SUpbut.setText("+");
SUpbut.setLocation(650,200);
SUpbut.setBackground(Color.WHITE);
SUpbut.setForeground(Color.BLACK);
SUpbut.setFont(new Font("Arial", 1, 50));
SUpbut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Sec++;
if (Sec > 59) {
Sec = 0;
}
AlarmSetHR.setText(TimeForm());
}
});

}
public void HrDownSwing() {
HrDownbut.setSize(275,40);
HrDownbut.setText("-");
HrDownbut.setLocation(100,500);
HrDownbut.setBackground(Color.WHITE);
HrDownbut.setForeground(Color.BLACK);
HrDownbut.setFont(new Font("Arial", 1, 50));
HrDownbut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Hr--;
if (Hr < 0) {
Hr = 24;
}
AlarmSetHR.setText(TimeForm());
}
});
}

public void MnDownSwing() {


MnDownbut.setSize(275,40);
MnDownbut.setText("-");
MnDownbut.setLocation(375,500);
MnDownbut.setBackground(Color.WHITE);
MnDownbut.setForeground(Color.BLACK);
MnDownbut.setFont(new Font("Arial", 1, 50));
MnDownbut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Min--;
if (Min < 0) {
Min = 59;
}
AlarmSetHR.setText(TimeForm());
}
});

public void SDownSwing() {


SDownbut.setSize(275,40);
SDownbut.setText("-");
SDownbut.setLocation(650,500);
SDownbut.setBackground(Color.WHITE);
SDownbut.setForeground(Color.BLACK);
SDownbut.setFont(new Font("Arial", 1, 50));
SDownbut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Sec--;
if (Sec < 0) {
Sec = 59;
}
AlarmSetHR.setText(TimeForm());
}
});

public void ButtonSwing() {


button.setSize(350,40);
button.setText("Set Alarm");
button.setLocation(340,580);
button.setBackground(Color.YELLOW);
button.addActionListener(new ButtonEvent());
}

public void LabelSwing() {

label.setSize(300,250);
label.setLocation(380,10);
label.setBackground(Color.WHITE);
label.setForeground(Color.BLUE);
label.setFont(newFont);
label.setVerticalAlignment(JLabel.TOP);
label.setVerticalTextPosition(JLabel.TOP);
label.setHorizontalAlignment(0);
updateTime();

public void updateTime() {


while(true) {
date = new Date();
label.setText("<html><font size='6' color='black'>&nbsp;"
+
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Alarm Clock</font><br>"
+ a + "<br>&nbsp;&nbsp;&nbsp;&nbsp;" + c
+"<br><font size='50' color='red'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
+ formh.format(date) + "</font>" + "<font
size='50' color='red'>:</font>"
+ "<font size='50' color='red'>"
+ formM.format(date) + "</font>" +
"<font size='50' color='red'>:</font>"
+ "<font size='50'
color='red'>"
+
forms.format(date) + "</font></html>") ;

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

public class FrameEvent extends WindowAdapter {

@Override
public void windowOpened(WindowEvent e) {
System.out.println("Opened");

}
}
public class ButtonEvent implements ActionListener {

@Override
public void actionPerformed(ActionEvent e) {
int a = JOptionPane.showConfirmDialog(null, "Are you
sure","Alarm", JOptionPane.YES_NO_OPTION);
if (a == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(null, "Confirmed");
} else {
JOptionPane.showMessageDialog(null, "Cancelled");
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy