import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class project
{
public static void main (String[] args)
{
WindowName frame = new WindowName();
frame.setSize (700, 300);
JPanel pane = (JPanel) frame.getContentPane();
frame.setVisible(true);
}
}
class WindowName extends JFrame implements ActionListener
{
private JTextField AFirstName;
private JTextField ALastName;
private JTextField Title;
private JTextField TodaysDate;
private JTextField UpdateDate;
private JTextField Url;
private JTextField totalName;
public WindowName ()
{
super("Bibliography Generator");//this will give the window the name of (:Bibliogaphy Generatot")
//Organized content pane
JPanel pane = (JPanel) getContentPane();
//Create fields for I/O
AFirstName = new JTextField(15);
ALastName = new JTextField(15);
Title = new JTextField (30);
TodaysDate= new JTextField(20);
UpdateDate = new JTextField(20);
Url = new JTextField(60);
totalName = new JTextField(60);
// add labbled input fields
JPanel inFieldPane = new JPanel();
JPanel inFieldPane2 = new JPanel();
inFieldPane.add (new JLabel("First Name"));
inFieldPane.add(AFirstName);
AFirstName.addActionListener(this);
inFieldPane.add(new JLabel ("Last Name"));
inFieldPane.add (ALastName);
ALastName.addActionListener (this);
inFieldPane.add(new JLabel ("Article Title"));
inFieldPane.add (Title);
Title.addActionListener (this);
inFieldPane2.add(new JLabel ("DD Mo. YYYY day viewed"));
inFieldPane2.add(TodaysDate);
TodaysDate.addActionListener (this);
inFieldPane2.add (new JLabel ("Last Published DD Mo. YYYY"));
inFieldPane2.add(UpdateDate);
UpdateDate.addActionListener (this);
inFieldPane2.add(new JLabel ("URL"));
inFieldPane2.add(Url);
Url.addActionListener (this);
pane.add(inFieldPane,BorderLayout.PAGE_START);
pane.add(inFieldPane2, BorderLayout.LINE_START);
// Add Submission Button
JPanel submitPane = new JPanel();
JButton submitButton = new JButton ("Generate!");
submitButton.addActionListener (this);
submitPane.add (submitButton);
pane.add(submitPane, BorderLayout.LINE_END);
//Add Output Fields
JPanel outFieldPane = new JPanel();
outFieldPane.add (totalName);
pane.add(outFieldPane, BorderLayout.PAGE_END );
//Display the final product
pack();
setVisible(true);
}
public void actionPerformed (ActionEvent e)
{
//Displays Authers total name if and only if button was pushed
if ( e.getActionCommand ().equals ("Generate!"))
{
String fullString = ALastName.getText().trim() + " , " + AFirstName.getText().trim() + ". " + Title.getText().trim()+ TodaysDate.getText ().trim()+ UpdateDate.getText ().trim()+ Url.getText().trim();
totalName.setText(fullString);
}
}
}
class Title extends JComponent // a class which is painting the main title (Biblio-Generator)
{
public Title ()
{
repaint();
}
public void paint (Graphics g)// method to draw the title
{
Font font = new Font("Serif", Font.ITALIC, 40);// changes the titles text font and size
g.setFont (font); //changes the font
g.drawString("Bibliography Generator ", 50,30);// locates the position of the title and outputs it in the window (draws title).
}
} |