Mystic Muse
2014-05-07, 01:15 PM
I'm having trouble with this assignment, and have basically hit a block. If somebody could help me get the program to compile, that'd be great.
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;
import java.util.*;
public class Transfer extends JFrame implements ActionListener
{
//Declare Output stream
DataOutputStream output;
//construct two panels
JPanel firstRow = new JPanel();
JPanel secondRow = new JPanel();
//construct a panel for the fields and buttons
JPanel fieldPanel = new JPanel();
JPanel buttonPanel = new JPanel();
//construct labels and textboxes
JLabel nameLabel = new JLabel("Name");
JTextfield name = new JTextField(15);
JLabel idLabel = new JLabel("Student ID");
JTextfield id = new JTextField(15);
JLabel transferLabel = new JLabel("Transer Course Number");
JTextfield transfer = new JTextField(15);
JLabel localLabel = new JLabel("Local Course Number");
JTextfield local = new JTextField(15);
//construct buttons
JButton submitButton = new JButton("Submit");
JButton exitButton = new JButton("Exit");
public static void main (String[] args)
{
//set the look and feel of the interface
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "The UIManager could not set the look and Feel for this application", "Error", JOptionPane.INFORMATION_MESSAGE);
}
Transfer f = new Transfer();
f.setDefaultCLoseOperation(JFrame.DO_NOTHING_ON_CL OSE);
f.setSize(450,300);
f.setTitle("Transfer Course Substitutions");
f.setResizable(false);
f.setLocation(200,200);
f.setVisible(true);
}
public Transfer()
{
}
public void actionPerformed(ActionEvent e)
{
}
}
public Transfer()
{
Container c = getContentPange();
c.setLayout((newBorderLayout()));
fieldPanel.setLayout(new GridLayout(8,1));
FlowLayout rowSetup = new FlowLayout (FlowLayout.Left,5,3);
firstRow.setLayout(rowSetup);
secondRow.setLayout(rowSetup);
thirdRow.setLayout(rowSetup);
fourthRow.setLayout(rowSetup);
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
}
public Transfer();
{
//add fields to rows
firstRow.add(nameLabel);
firstRow.add(name);
secondRow.add(idLabel);
secondRow.add(id);
thirdRow.add(transfercourseLabel);
thirdRow.add(transfercourse);
fourthRow.add(localLabel);
fourthRow.add(local);
//Add rows to panel
fieldPanel.add(firstRow);
fieldPanel.add(secondRow);
fieldPanel.add(thirdRow);
fieldPanel.add(fourthRow);
//Add buttons to panel
buttonPanel.add(submitButton);
buttonPanel.add(exitButton);
//Add panels to frame
c.add(fieldPanel, BorderLayout.CENTER);
c.add(buttonPanel, BorderLayout.SOUTH);
//Add functionality to buttons
submtiButton.addActionListener(this);
exitButton.addActionListener(this);
try
{
output = new DataOutputStream(new FileOutputStream(transfer.dat));
}
catch(IOException ex)
{
JOptionPane.showMessageDialog(null,"", "Error", JOptionPane.INFORMATION_MESSAGE);
System.exit(1)
}
addWindowListener(
newWindowAdapter()
{
public void windowClosing(WindowEvent e)
{
int answer = JOptionPane.showConfirmDialog(null,"Are you sure you want to exit and submit the file?" "File Submission", JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.YES_OPTION)
System.exit(0);
}
}
);
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
if (checkFields())
{
try
{
output.writeUTF(name.getText());
output.writeUTF(id.getText());
output.writeUTF(transfercourse.getText());
output.writeUTF(local.getText());
JOptionPane.showMessageDialog(null, "","Submission Successful",JOptionPane.INFORMATION_MESSAGE
}
catch(IOException ex)
{
System.exit(1);
}
clearFields();
}
}
else //code to execute if the user clicks Exit
{
try
{
output.close();
}
catch(IOException c)
{
System.exit(1);
}
System.exit(0);
}
public void clearFields()
{
//Clear fields and reset the focus
name.setText("");
id.setText("");
transfer.setText("");
local.setText("");
name.requestFocus();
}
}
C:\Users\Caleb\Desktop\Transfer.java:77: 'class' or 'interface' expected
public Transfer()
^
C:\Users\Caleb\Desktop\Transfer.java:91: 'class' or 'interface' expected
{
^
2 errors
If anyone can help, that'd be great.
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;
import java.util.*;
public class Transfer extends JFrame implements ActionListener
{
//Declare Output stream
DataOutputStream output;
//construct two panels
JPanel firstRow = new JPanel();
JPanel secondRow = new JPanel();
//construct a panel for the fields and buttons
JPanel fieldPanel = new JPanel();
JPanel buttonPanel = new JPanel();
//construct labels and textboxes
JLabel nameLabel = new JLabel("Name");
JTextfield name = new JTextField(15);
JLabel idLabel = new JLabel("Student ID");
JTextfield id = new JTextField(15);
JLabel transferLabel = new JLabel("Transer Course Number");
JTextfield transfer = new JTextField(15);
JLabel localLabel = new JLabel("Local Course Number");
JTextfield local = new JTextField(15);
//construct buttons
JButton submitButton = new JButton("Submit");
JButton exitButton = new JButton("Exit");
public static void main (String[] args)
{
//set the look and feel of the interface
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "The UIManager could not set the look and Feel for this application", "Error", JOptionPane.INFORMATION_MESSAGE);
}
Transfer f = new Transfer();
f.setDefaultCLoseOperation(JFrame.DO_NOTHING_ON_CL OSE);
f.setSize(450,300);
f.setTitle("Transfer Course Substitutions");
f.setResizable(false);
f.setLocation(200,200);
f.setVisible(true);
}
public Transfer()
{
}
public void actionPerformed(ActionEvent e)
{
}
}
public Transfer()
{
Container c = getContentPange();
c.setLayout((newBorderLayout()));
fieldPanel.setLayout(new GridLayout(8,1));
FlowLayout rowSetup = new FlowLayout (FlowLayout.Left,5,3);
firstRow.setLayout(rowSetup);
secondRow.setLayout(rowSetup);
thirdRow.setLayout(rowSetup);
fourthRow.setLayout(rowSetup);
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
}
public Transfer();
{
//add fields to rows
firstRow.add(nameLabel);
firstRow.add(name);
secondRow.add(idLabel);
secondRow.add(id);
thirdRow.add(transfercourseLabel);
thirdRow.add(transfercourse);
fourthRow.add(localLabel);
fourthRow.add(local);
//Add rows to panel
fieldPanel.add(firstRow);
fieldPanel.add(secondRow);
fieldPanel.add(thirdRow);
fieldPanel.add(fourthRow);
//Add buttons to panel
buttonPanel.add(submitButton);
buttonPanel.add(exitButton);
//Add panels to frame
c.add(fieldPanel, BorderLayout.CENTER);
c.add(buttonPanel, BorderLayout.SOUTH);
//Add functionality to buttons
submtiButton.addActionListener(this);
exitButton.addActionListener(this);
try
{
output = new DataOutputStream(new FileOutputStream(transfer.dat));
}
catch(IOException ex)
{
JOptionPane.showMessageDialog(null,"", "Error", JOptionPane.INFORMATION_MESSAGE);
System.exit(1)
}
addWindowListener(
newWindowAdapter()
{
public void windowClosing(WindowEvent e)
{
int answer = JOptionPane.showConfirmDialog(null,"Are you sure you want to exit and submit the file?" "File Submission", JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.YES_OPTION)
System.exit(0);
}
}
);
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
if (checkFields())
{
try
{
output.writeUTF(name.getText());
output.writeUTF(id.getText());
output.writeUTF(transfercourse.getText());
output.writeUTF(local.getText());
JOptionPane.showMessageDialog(null, "","Submission Successful",JOptionPane.INFORMATION_MESSAGE
}
catch(IOException ex)
{
System.exit(1);
}
clearFields();
}
}
else //code to execute if the user clicks Exit
{
try
{
output.close();
}
catch(IOException c)
{
System.exit(1);
}
System.exit(0);
}
public void clearFields()
{
//Clear fields and reset the focus
name.setText("");
id.setText("");
transfer.setText("");
local.setText("");
name.requestFocus();
}
}
C:\Users\Caleb\Desktop\Transfer.java:77: 'class' or 'interface' expected
public Transfer()
^
C:\Users\Caleb\Desktop\Transfer.java:91: 'class' or 'interface' expected
{
^
2 errors
If anyone can help, that'd be great.