CSC101-Assignment 1 (Ch. 1 & 2) Complete the following programs and zip the enti
ID: 3909954 • Letter: C
Question
CSC101-Assignment 1 (Ch. 1 & 2) Complete the following programs and zip the entire folder for each program onto one single compressed file. Then use the same link under Assignments button to submit your zipped file. Important Notice: Remember to include some comments inside your program. 1. 15 pts) Look at the following list of Latin words and their meanings. Latin English eft right Create an application that translates the Latin words to English. The form should have three buttons, one for each Latin word. When the user clicks a button, the application should display the English translations in a Label control. The screens shown in below figure show an example of the application running. The top-left screen shows the application when it starts. The other screens show the application after the user has clicked one of the buttons. Latin Translator - × Latin Translator- Left Latin Translator x Latin Translator- X Middle Right Nedun Ext Ext 2. 25 pts) Create an application (design your own GUI interface) that allows the user to selecta state and then display that state's official abbreviation. The form should have six buttons, one for each state. When the user clicks a button, the application displays the state's abbreviation in a Label controlExplanation / Answer
//Translation java file
import javax.swing.*;
import java.awt.event.*;
public class Translation implements ActionListener
{
JFrame f;
JLabel l;
JButton b1,b2,b3,b4;
Translation()
{
f=new JFrame("Latin Translation");
l = new JLabel("",SwingConstants.CENTER);
b1=new JButton("Sinister");
b2=new JButton("Medium");
b3=new JButton("Dexter");
b4=new JButton("Exit");
l.setBounds(140,50,100,30);
b1.setBounds(20,100,100,30);
b2.setBounds(140,100,100,30);
b3.setBounds(260,100,100,30);
b4.setBounds(140,150,100,30);
f.add(l);
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public void actionPerformed(ActionEvent event)
{
JButton b=(JButton)event.getSource();
if(b==b1)
l.setText("Left");
if(b==b2)
l.setText("Middle");
if(b==b3)
l.setText("Right");
else if(b==b4)
{
f.dispose();
System.exit(0);
}
}
public static void main(String args[])
{
new Translation();
}
}
//States Abbreviation java file
import javax.swing.*;
import java.awt.event.*;
public class StatesAbbreviation implements ActionListener
{
JFrame f;
JLabel l;
JButton b1,b2,b3,b4,b5,b6,b7;
StatesAbbreviation()
{
f=new JFrame("States Abbreviation");
l = new JLabel("",SwingConstants.CENTER);
b1=new JButton("VA");
b2=new JButton("NC");
b3=new JButton("SC");
b4=new JButton("GA");
b5=new JButton("AL");
b6=new JButton("FL");
b7=new JButton("Exit");
l.setBounds(160,50,100,30);
b1.setBounds(20,100,50,30);
b2.setBounds(90,100,50,30);
b3.setBounds(160,100,50,30);
b4.setBounds(230,100,50,30);
b5.setBounds(300,100,50,30);
b6.setBounds(370,100,50,30);
b7.setBounds(160,150,100,30);
f.add(l);
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
f.add(b6);
f.add(b7);
f.setSize(450,400);
f.setLayout(null);
f.setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
}
public void actionPerformed(ActionEvent event)
{
JButton b=(JButton)event.getSource();
if(b==b1)
l.setText("Virginia");
else if(b==b2)
l.setText("North Carolina");
else if(b==b3)
l.setText("South Carolina");
else if(b==b4)
l.setText("Georgia");
else if(b==b5)
l.setText("Alabama");
else if(b==b6)
l.setText("Florida");
else if(b==b7)
{
f.dispose();
System.exit(0);
}
}
public static void main(String args[])
{
new StatesAbbreviation();
}
}