// Main Class which displays the first Window
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame
{
private JLabel intoLbl;
private JButton enterBtn;
private JButton exitBtn;
private JPanel contentPane;
public Font font = new Font("Algerian", Font.BOLD, 24);
public Main()
{
super();
initializeComponent();
this.setVisible(true);
}
private void initializeComponent()
{
intoLbl = new JLabel();
enterBtn = new JButton();
exitBtn = new JButton();
contentPane = (JPanel)this.getContentPane();
intoLbl.setFont(font);
enterBtn.setFont(font);
enterBtn.setBackground(Color.GREEN);
exitBtn.setFont(font);
intoLbl.setText("BEN SAM WEATHER STATION");
enterBtn.setText("CAPTURE FORECAST");
enterBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
new CaptureFrame();
}
});
exitBtn.setText("EXIT");
exitBtn.setBackground(Color.WHITE);
exitBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
contentPane.setLayout(null);
contentPane.setBackground(Color.WHITE);
addComponent(contentPane, intoLbl, 170,10,400,15);
addComponent(contentPane, enterBtn, 0,30,729,406);
addComponent(contentPane, exitBtn, 0,436,729,28);
this.setTitle("WEATHER CAPTURE SYSTEM");
this.setLocation(new Point(300, 100));
this.setSize(new Dimension(729, 496));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
public static void main(String[] args)
{
new Main();
}
}
//CaptureFrame Class - Displays the input window, which prompts the analyst to capture the focust
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CaptureFrame extends JFrame
{
private JButton sbtBtn;
private JButton extBtn;
private JButton clrBtn;
private JButton viewBtn;
private JPanel contentPane;
public CaptureFrame()
{
super();
initializeComponent();
this.setVisible(true);
}
private void initializeComponent()
{
sbtBtn = new JButton();
extBtn = new JButton();
clrBtn = new JButton();
viewBtn = new JButton();
contentPane = (JPanel)this.getContentPane();
sbtBtn.setText("Submit");
sbtBtn.setToolTipText("Press This Button To Save");
sbtBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
new Submit();
}
});
extBtn.setText("Exit");
extBtn.setToolTipText("Press The Button To Exit");
extBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
clrBtn.setText("Clear");
clrBtn.setToolTipText("Press To Clear");
clrBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
new ClearCommand();
}
});
viewBtn.setText("View Weather");
viewBtn.setToolTipText("Press The Button To View The Entries");
viewBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
new ViewCommand();
}
});
contentPane.setLayout(null);
contentPane.setBackground(new Color(5, 250, 10));
addComponent(contentPane, new InputPanel(), 0,0,400,620);
addComponent(contentPane, sbtBtn, 35,620,83,28);
addComponent(contentPane, extBtn, 35,650,83,28);
addComponent(contentPane, clrBtn, 135,635,83,28);
addComponent(contentPane, viewBtn, 235,635,115,26);
this.setTitle("WEATHER CAPTURE SYSTEM");
this.setLocation(new Point(300, 0));
this.setSize(new Dimension(400, 720));
}
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
}
//InputPanel Class-the panel that contains labels and textfields for input. This panel is displayed by CaptureFrame
import java.awt.*;
import javax.swing.*;
public class InputPanel extends JPanel {
public static JTextField date, chichTemp, chichHum, chichRain, mimTemp, mimHum, mimRain;
public static JTextField bundaTemp, bundaHum, bundaRain, kiaTemp, kiaHum, kiaRain, mzuTemp, mzuHum, mzuRain;
public InputPanel()
{
setBackground(Color.green);
setLayout(new GridBagLayout());
//DATE
JLabel dateLbl = new JLabel ("Date");
date = new JTextField(10);
dateLbl.setFont(new Font("algerian",Font.BOLD,20));
addItem(this, dateLbl, 0, 0, 1, 1, GridBagConstraints.WEST);
addItem(this, date, 0, 0, 1, 1, GridBagConstraints.CENTER);
//CHICHIRI
JLabel chichLbl = new JLabel ("Chichiri");
chichLbl.setFont(new Font("algerian",Font.BOLD,20));
JLabel chichHumidLbl = new JLabel ("Humidity");
JLabel chichTempLbl = new JLabel ("Temperature");
JLabel chichRainLbl = new JLabel ("Rainfall");
chichHum = new JTextField(10);
chichTemp = new JTextField(10);
chichRain = new JTextField(10);
addItem(this, chichLbl, 0, 2, 1, 1, GridBagConstraints.WEST);
addItem(this, chichHumidLbl, 0, 2, 1, 1, GridBagConstraints.CENTER);
addItem(this, chichHum, 0, 2, 1, 1, GridBagConstraints.EAST);
addItem(this, chichTempLbl, 0, 3, 1, 1, GridBagConstraints.CENTER);
addItem(this, chichRainLbl, 0, 4, 1, 1, GridBagConstraints.CENTER);
addItem(this, chichTemp, 0, 3, 1, 1, GridBagConstraints.EAST);
addItem(this, chichRain, 0, 4, 1, 1, GridBagConstraints.EAST);
//MIMOSA
JLabel mimLbl = new JLabel ("Mimosa");
mimLbl.setFont(new Font("algerian",Font.BOLD,20));
JLabel mimHumidLbl = new JLabel ("Humidity");
JLabel mimTempLbl = new JLabel ("Temperature");
JLabel mimRainLbl = new JLabel ("Rainfall");
mimHum = new JTextField(10);
mimTemp = new JTextField(10);
mimRain = new JTextField(10);
addItem(this, mimLbl, 0, 6, 1, 1, GridBagConstraints.WEST);
addItem(this, mimHumidLbl, 0, 6, 1, 1, GridBagConstraints.CENTER);
addItem(this, mimHum, 0, 6, 1, 1, GridBagConstraints.EAST);
addItem(this, mimTempLbl, 0, 7, 1, 1, GridBagConstraints.CENTER);
addItem(this, mimRainLbl, 0, 8, 1, 1, GridBagConstraints.CENTER);
addItem(this, mimTemp, 0, 7, 1, 1, GridBagConstraints.EAST);
addItem(this, mimRain, 0, 8, 1, 1, GridBagConstraints.EAST);
//BUNDA
JLabel bundaLbl = new JLabel ("Bunda");
bundaLbl.setFont(new Font("algerian",Font.BOLD,20));
JLabel bundaHumidLbl = new JLabel ("Humidity");
JLabel bundaTempLbl = new JLabel ("Temperature");
JLabel bundaRainLbl = new JLabel ("Rainfall");
bundaHum = new JTextField(10);
bundaTemp = new JTextField(10);
bundaRain = new JTextField(10);
addItem(this, bundaLbl, 0, 10, 1, 1, GridBagConstraints.WEST);
addItem(this, bundaHumidLbl, 0, 10, 1, 1, GridBagConstraints.CENTER);
addItem(this, bundaHum, 0, 10, 1, 1, GridBagConstraints.EAST);
addItem(this, bundaTempLbl, 0, 11, 1, 1, GridBagConstraints.CENTER);
addItem(this, bundaRainLbl, 0, 12, 1, 1, GridBagConstraints.CENTER);
addItem(this, bundaTemp, 0, 11, 1, 1, GridBagConstraints.EAST);
addItem(this, bundaRain, 0, 12, 1, 1, GridBagConstraints.EAST);
//KIA
JLabel kiaLbl = new JLabel ("KIA");
kiaLbl.setFont(new Font("algerian",Font.BOLD,20));
JLabel kiaHumidLbl = new JLabel ("Humidity");
JLabel kiaTempLbl = new JLabel ("Temperature");
JLabel kiaRainLbl = new JLabel ("Rainfall");
kiaHum = new JTextField(10);
kiaTemp = new JTextField(10);
kiaRain = new JTextField(10);
addItem(this, kiaLbl, 0, 14, 1, 1, GridBagConstraints.WEST);
addItem(this, kiaHumidLbl, 0, 14, 1, 1, GridBagConstraints.CENTER);
addItem(this, kiaHum, 0, 14, 1, 1, GridBagConstraints.EAST);
addItem(this, kiaTempLbl, 0, 15, 1, 1, GridBagConstraints.CENTER);
addItem(this, kiaRainLbl, 0, 16, 1, 1, GridBagConstraints.CENTER);
addItem(this, kiaTemp, 0, 15, 1, 1, GridBagConstraints.EAST);
addItem(this, kiaRain, 0, 16, 1, 1, GridBagConstraints.EAST);
//MZUNI
JLabel mzuLbl = new JLabel ("MZUNI");
mzuLbl.setFont(new Font("algerian",Font.BOLD,20));
JLabel mzuHumidLbl = new JLabel ("Humidity");
JLabel mzuTempLbl = new JLabel ("Temperature");
JLabel mzuRainLbl = new JLabel ("Rainfall");
mzuHum = new JTextField(10);
mzuTemp = new JTextField(10);
mzuRain = new JTextField(10);
addItem(this, mzuLbl, 0, 18, 1, 1, GridBagConstraints.WEST);
addItem(this, mzuHumidLbl, 0, 18, 1, 1, GridBagConstraints.CENTER);
addItem(this, mzuHum, 0, 18, 1, 1, GridBagConstraints.EAST);
addItem(this, mzuTempLbl, 0, 19, 1, 1, GridBagConstraints.CENTER);
addItem(this, mzuRainLbl, 0, 20, 1, 1, GridBagConstraints.CENTER);
addItem(this, mzuTemp, 0, 19, 1, 1, GridBagConstraints.EAST);
addItem(this, mzuRain, 0, 20, 1, 1, GridBagConstraints.EAST);
}
private static void addItem(JPanel p, JComponent c,int x, int y, int width, int height, int align)
{
GridBagConstraints gridBag = new GridBagConstraints();
gridBag.gridx = x;
gridBag.gridy = y;
gridBag.gridwidth = width;
gridBag.gridheight = height;
gridBag.weightx = 10;
gridBag.weighty = 10;
gridBag.insets = new Insets(8, 8, 5, 0);
gridBag.anchor = align;
gridBag.fill = GridBagConstraints.NONE;
p.add(c, gridBag);
}
}
//Submit Class - Displays the save dialogue box
import javax.swing.*;
public class Submit {
public Submit() {
ViewCommand viewCommand = new ViewCommand("No Frame Display");
String data = viewCommand.myArea.getText();
String[] lines = data.split("\n");
//System.out.print(data);
JFileChooser fileChooser = new JFileChooser();
int result = fileChooser.showSaveDialog(null);
if(result == JFileChooser.APPROVE_OPTION)
{
File file;
String fileName = fileChooser.getSelectedFile().getName();
file = new File(fileName + ".txt");
if (file.exists())
{
JOptionPane.showMessageDialog(null, "File already exists");
}
else try
{
FileWriter fw = new FileWriter(file, true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw, true);
for(int i = 0; i < 26; i++) {
out.println(lines[i]);
}
out.flush();
out.close();
}
catch(IOException exp){}
}
}
}
//ViewCommand Class - Displays the preview of the forecast
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ViewCommand {
final JFrame viewFrame= new JFrame();
JPanel myPanel = new JPanel ();
JTextArea myArea = new JTextArea(18,25);
public ViewCommand() {
this(null);
}
public ViewCommand(String print) {
display();
setViewFrame();
if (print == null) {
viewFrame.setVisible(true);
}
else {
viewFrame.setVisible(false);
}
}
public void setViewFrame() {
viewFrame.setTitle("WEATHER FORECAST");
JButton okBtn = new JButton("Ok");
okBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
viewFrame.setVisible(false);
}
});
myPanel.add(myArea, BorderLayout.CENTER);
myPanel.add(okBtn, BorderLayout.SOUTH);
viewFrame.setLocation(700,50);
viewFrame.setResizable(false);
viewFrame.pack();
}
public void display() {
myPanel.setLayout(new BorderLayout(2,2));
viewFrame.setContentPane(myPanel);
myArea.append(" DATE: "+ InputPanel.date.getText()+"\n\n");
myArea.append("********************CHCHIRI**********************"+"\n");
myArea.append("HUMIDITY: "+ InputPanel.chichHum.getText()+"\n");
myArea.append("TEMPERATURE: "+ InputPanel.chichTemp.getText()+"\n");
myArea.append("RAINFALL: "+ InputPanel.chichRain.getText()+"\n\n");
myArea.append("*******************MIMOSA***********************"+"\n");
myArea.append("HUMIDITY: "+ InputPanel.mimHum.getText() + "\n");
myArea.append("TEMPERATURE: "+ InputPanel.mimTemp.getText()+"\n");
myArea.append("RAINFALL: "+ InputPanel.mimRain.getText()+"\n\n");
myArea.append("*********************BUNDA***********************"+"\n");
myArea.append("HUMIDITY:"+ InputPanel.bundaHum.getText()+"\n");
myArea.append("TEMPERATURE: "+ InputPanel.bundaTemp.getText()+"\n");
myArea.append("RAINFALL: "+ InputPanel.bundaRain.getText()+"\n\n");
myArea.append("*************************KIA************************"+"\n");
myArea.append("HUMIDITY: "+ InputPanel.kiaHum.getText()+"\n");
myArea.append("TEMPERATURE: "+ InputPanel.kiaTemp.getText()+"\n");
myArea.append("RAINFALL: "+ InputPanel.kiaRain.getText()+"\n\n");
myArea.append("***********************MZUNI**********************"+"\n");
myArea.append("HUMIDITY: "+ InputPanel.mzuHum.getText()+"\n");
myArea.append("TEMPERATURE: "+ InputPanel.mzuTemp.getText()+"\n");
myArea.append("RAINFALL: "+ InputPanel.mzuRain.getText());
myArea.setEditable(false);
myArea.setFont(new Font("algerian",Font.BOLD,15));
myArea.setBackground(Color.green);
}
}
//ClearCommand Class - Clears the textfields
import javax.swing.JOptionPane;
public class ClearCommand {
public ClearCommand() {
String blank = new String("");
InputPanel.date.setText(blank);
InputPanel.chichTemp.setText(blank);
InputPanel.chichHum.setText(blank);
InputPanel.chichRain.setText(blank);
InputPanel.mimTemp.setText(blank);
InputPanel.mimHum.setText(blank);
InputPanel.mimRain.setText(blank);
InputPanel.bundaTemp.setText(blank);
InputPanel.bundaHum.setText(blank);
InputPanel.bundaRain.setText(blank);
InputPanel.kiaTemp.setText(blank);
InputPanel.kiaHum.setText(blank);
InputPanel.kiaRain.setText(blank);
InputPanel.mzuTemp.setText(blank);
InputPanel.mzuHum.setText(blank);
InputPanel.mzuRain.setText(blank);
JOptionPane.showMessageDialog(null, "YOUR FORECASTS HAS BEEN CLEARED");
}
}