rendered paste bodyimport java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Container;
import javax.swing.*;
import java.text.SimpleDateFormat;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class announcement implements ActionListener
{
protected JTextArea textArea;
protected JTextField textField;
public JFrame frame;
public boolean started = true;
private PlayerHandler c;
private final static String newline = "\n";
private final static String announcement = "";
public String date = new SimpleDateFormat("MM/dd/yyyy").format(new Date());
public String time = new SimpleDateFormat("hh:mm:ss").format(new Date());
public static void main()
{
new announcement();
}
public announcement()
{
try
{
gui(true);
textArea.append("AnnouncementGUI Started Successfully" + newline);
textArea.append("Made By ShadowShaft" + newline);
}
catch(Exception e)
{
gui(false);
textArea.append("AnnouncementGUI Failed To Start" + newline);
}
}
public void gui(boolean show)
{
JFrame.setDefaultLookAndFeelDecorated(true);
int windowWidth = 600;
int windowHeight = 250;
frame = new JFrame("Anncouncement By ShadowShaft");
textArea = new JTextArea();
textField = new JTextField();
frame.setBounds(100, 200, windowWidth, windowHeight);
frame.setResizable(false);
frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
frame.setVisible(show);
frame.add(textArea, "North");
frame.add(textField, "South");
textArea();
textField();
}
public void textArea() {
color(textArea, Color.black, Color.white);
Font f = new Font("Arial", Font.PLAIN, 12);
textArea.setFont(f);
int windowWidth = 5;
int windowHeight = 5;
textArea.setEditable(false);
}
public void textField() {
int windowWidth = 10;
int windowHeight = 10;
textField.addActionListener(this);
}
public void actionPerformed(ActionEvent evt) {
String text = textField.getText();
textArea.append(announcement + text + newline);
logs(text, "AnnouncementSave");
c.messageToAll = (announcement + text);
textField.selectAll();
textArea.setCaretPosition(textArea.getDocument().getLength());
}
public void color(JTextArea name, Color f, Color b)
{
name.setForeground(f);
name.setBackground(b);
}
public void logs(String i, String path)
{
BufferedWriter bw2 = null;
String location = "./data/"+ path +".txt";
try
{
File bwt = new File(location);
bw2 = new BufferedWriter(new FileWriter(location, true));
bw2.write("On "+ date +" At "+ time);
bw2.newLine();
bw2.write(announcement + i);
bw2.newLine();
bw2.newLine();
bw2.flush();
}
catch(IOException e)
{
announcementsave();
}
}
public void announcementsave()
{
BufferedWriter bw2 = null;
String location = "./data/AnnouncementSave.txt";
try
{
File bwt = new File(location);
bw2 = new BufferedWriter(new FileWriter(location, true));
bw2.write("On "+ date +" At "+ time +" Error with public void logs(String,String)");
bw2.newLine();
bw2.flush();
}
catch(IOException e)
{
textArea.append(" Error to save Announcement()");
}
}
}