Question

JAVA Developing a graphical user interface in programming is paramount to being successful in the business...

JAVA

Developing a graphical user interface in programming is paramount to being successful in the business industry. This project incorporates GUI techniques with other tools that you have learned about in this class.

Here is your assignment: You work for a flooring company. They have asked you to be a part of their team because they need a computer programmer, analyst, and designer to aid them in tracking customer orders. Your skills will be needed in creating a GUI program that calculates the flooring cost and stores the order in the database.

Your application must include at least three tabs. The user will choose wood flooring or carpet, enter the length and width of the floor, as well as the customer name and address. The application will compute the area of the floor and the cost of the flooring considering that wood floor is $20 per square foot and carpet is $10 per square foot. A summary should be displayed, either in a tab or another window, listing the customer name and address, floor selection, area, and cost. This information should also be stored in the MySQL database table. The program should validate that all information is entered and that the length and width are numeric values. Any numeric or currency values must be formatted appropriately when output. Recommendations for the components used for input are

radio buttons—flooring type (wood or carpet);

text fields—customer name, customer address, floor length, and floor width; and

buttons—calculate area, calculate cost, submit order, display order summary, display order list.

The MySQL database table is called flooring and has the following description.

Field

Type

CustomerName

varchar(30)

CustomerAddress

varchar(50)

FlooringType

varchar(10)

FloorArea

double

FloorCost

double

In addition to entering new customer orders, your application should list all customer orders stored in the database. These will be viewed as a list, in a text area, and will not be updated by the user.

You will use the guidelines described above and the grading rubric below to complete this document. You will create the following items.

1. Request for new application = Done

2. Problem analysis = Done

3. List and description of the requirements = Done

4. Interface storyboard or drawing = Done

5. Design flowchart or pseudocode - Needing assistance.

6. Create code in JAVA

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Sample Output:

Create the Database as follows:

Form Tab Floor type:

Form Tab Length & Width:

Form Tab Customer:

Database After Last Submit:

Code to copy:

Note: First select one of the radio button then click on calculate area and cost by selecting the tab length and Width.

FlooringCompanyGUI.java:

//Import the required packages.

import java.sql.*;

import java.awt.event.*;

import javax.swing.*;

import java.awt.*;

//Define the class.

class FlooringCompanyGUI extends JFrame implements

ActionListener, ItemListener

{

//Craete an object of jTab.

JTabbedPane jtab;

//Create radio button and button group.

JRadioButton rdowood, rdocarpet;

ButtonGroup bg = new ButtonGroup();

//Add different jcomponent.

JTextField txtcname, txtaddress, txtlength, txtwidth;

JButton btncalculate, btncost, btnsubmitorder,

btnordersummary, btnorderlist;

JPanel floorpanel, lwpanel, customerpanel;

JLabel l1, l2, l3, l4;

String floortype = "";

JTextArea ar1 = new JTextArea("");

// Define the variable for

// establishing the database connectivity.

Connection conn;

PreparedStatement pt;

double area = 0, cost = 0;

//Define the constructor.

FlooringCompanyGUI(String title)

{

super(title);

//Create the JTab.

jtab = new JTabbedPane();

//Craete three Panels.

floorpanel = new JPanel();

lwpanel = new JPanel();

customerpanel = new JPanel();

//Add the content to floor Panel.

floorpanel.add(rdowood = new JRadioButton("Wood"));

floorpanel.add(rdocarpet = new JRadioButton("Carpet"));

//Add the content to Length Width Panel.

lwpanel.add(l1 = new JLabel("Enter length : "));

lwpanel.add(txtlength = new JTextField(10));

lwpanel.add(l2 = new JLabel("Enter width : "));

lwpanel.add(txtwidth = new JTextField(10));

lwpanel.add(btncalculate = new JButton("Calculate Area"));

lwpanel.add(btncost = new JButton("Calculate Cost"));

//Add the content to the customer Panel.

customerpanel.add(l3 = new JLabel("Enter customer name : "));

customerpanel.add(txtcname = new JTextField(10));

customerpanel.add(l4 = new JLabel("Enter customer address : "));

customerpanel.add(txtaddress = new JTextField(10));

customerpanel.add(btnordersummary = new JButton("Order Summary"));

customerpanel.add(btnsubmitorder = new JButton("Submit Order"));

customerpanel.add(btnorderlist = new JButton("Order List"));

customerpanel.add(ar1);

//Add the panel to the tab.

jtab.addTab("Floor type", floorpanel);

jtab.addTab("Length & Width ", lwpanel);

jtab.addTab("Customer", customerpanel);

//Add Tab in the frame.

add(jtab);

//Add the radiobutton to button group bg.

bg.add(rdowood);

bg.add(rdocarpet);

//Add item listener to the buttons.

btncalculate.addActionListener(this);

btncost.addActionListener(this);

btnsubmitorder.addActionListener(this);

btnordersummary.addActionListener(this);

btnorderlist.addActionListener(this);

rdowood.addItemListener(this);

rdocarpet.addItemListener(this);

}

//Define the method to set string for the

//selected radiobutton.

public void itemStateChanged(ItemEvent ie)

{

if (rdowood.isSelected())

floortype = "Wood";

else

floortype = "Carpet";

}

//Define the method to add data to the database.

public void insert() {

try {

// Connect with the database.

Class.forName("com.mysql.jdbc.Driver");

conn = DB.connectDb();

// Write the insert query script.

String qur = "insert into flooring(CustomerName,CustomerAddress,"

+ " FlooringType, FloorArea,FloorCost ) values(?,?,?,?,?)";

// Add the record in the database.

pt = conn.prepareStatement(qur, Statement.RETURN_GENERATED_KEYS);

pt.setString(1, txtcname.getText());

pt.setString(2, txtaddress.getText());

pt.setString(3, floortype);

pt.setDouble(4, area);

pt.setDouble(5, cost);

int i = pt.executeUpdate();

// If insertion is successfull display the

// message and display the table.

if (i > 0) {

JOptionPane.showMessageDialog(null, "Record Added");

}

// Otherwise dispaly the message failed.

else {

JOptionPane.showMessageDialog(null, "Failed");

}

} catch (ClassNotFoundException | SQLException | HeadlessException e) {

JOptionPane.showMessageDialog(null, e);

}

}

//Define the method to perform the events.

public void actionPerformed(ActionEvent ae)

{

String source = ae.getActionCommand();

//The condition to calculate the area.

if (source.equals("Calculate Area"))

{

//Check if the length and width are numeric values.

if (txtlength.getText().matches("-?\\d+(\\.\\d+)?")

&& txtwidth.getText().matches("-?\\d+(\\.\\d+)?"))

{

//Calculate the area.

area = Double.parseDouble(txtlength.getText()) *

Double.parseDouble(txtwidth.getText());

JOptionPane.showMessageDialog(null, "Area is "

+ area + " square foot");

}

//Otherwise display the message.

else {

JOptionPane.showMessageDialog(null, "length and width must be numeric");

}

}

//The condition to calculate the cost.

else if (source.equals("Calculate Cost")) {

System.out.println("Hello2");

if (floortype.equals("Wood"))

cost = area * 20;

else if (floortype.equals("Carpet"))

cost = area * 10;

JOptionPane.showMessageDialog(null, "Cost is $" + cost);

}

//Display the order summary on click of order summary button.

else if (source.equals("Order Summary")) {

JOptionPane.showMessageDialog(null,

"Order List : \n Customer name: " + txtcname.getText()

+ "\nAddress : " + txtaddress.getText()

+ "\nFlooring Type:" + floortype + "\n Area is :"

+ area + "\n Cost is : " + cost,

"Information", JOptionPane.INFORMATION_MESSAGE);

}

//Call the method and display the list of records.

else if (source.equals("Order List")) {

PopulatejList();

}

//Condition for submit order button.

else if (source.equals("Submit Order"))

{  

//Check if all the textfield are filled.

if (txtlength.getText().isEmpty() ||

txtwidth.getText().isEmpty() ||

txtcname.getText().isEmpty()

|| txtaddress.getText().isEmpty()

|| floortype.isEmpty()) {

JOptionPane.showMessageDialog(null,

"No textbox can be empty");

}

//Add the record in the database.

else

{

insert();

}

}

}

//Create the string list.

DefaultListModel<String> list = new DefaultListModel<>();

//Define the method to populate the list.

public void PopulatejList()

{

String qur, n, a, ft;

double ar;

double c;

conn = DB.connectDb();

//Add the header to the list.

list.addElement("CustomerName" + "\tCustomerAddress"

+ "\tFlooringType" + "\tFloorArea" + "\tFloorCost" + "\n");

try {

// Write the query.

qur = "select * from flooring";

pt = conn.prepareStatement(qur);

// Execute the query.

ResultSet rs1 = pt.executeQuery();

while (rs1.next())

{

n = rs1.getString(1);

a = rs1.getString(2);

ft = rs1.getString(3);

ar = rs1.getDouble(4);

c = rs1.getDouble(5);

String add = n + "\t\t" + a + "\t" + ft

+ "\t" + ar + "\t" + c + "\n";

//Add the record to the list.

list.addElement(add);

}

//Display the content of the list in Jtextarea.

ar1.setText("" + list);

}

catch (SQLException e) {

JOptionPane.showMessageDialog(null, e.getMessage(),

"Communication Error", JOptionPane.WARNING_MESSAGE);

}

}

//Define the main method.

public static void main(String args[])

{

//Create the object of the class.

FlooringCompanyGUI f1 =

new FlooringCompanyGUI("Flooring Software");

//Define the framesize.

f1.setSize(new Dimension(900, 500));

//Make the frame visible.

f1.setVisible(true);

}

}

DB.java:

//Import the required packages.

import java.sql.*;

import javax.swing.*;

//Define the class.

public class DB {

//Define and set the variables for

//database connectivity.

public static String dbName =

"jdbc:mysql://localhost/flooring";

public static String dbUserName = "root";

public static String dbPassword = "";

//Create the method for

//database connectivity

public static Connection connectDb()

{

//Establish the connection.

try{

Class.forName("com.mysql.jdbc.Driver");

Connection conn=DriverManager.getConnection

(DB.dbName,DB.dbUserName,

DB.dbPassword);

return conn;

}

  

//Display the message if connectivity fails.

catch(ClassNotFoundException | SQLException e)

{

JOptionPane.showMessageDialog(null, e);

return null;

}

}

}

Add a comment
Know the answer?
Add Answer to:
JAVA Developing a graphical user interface in programming is paramount to being successful in the business...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I. User Interface Create a JavaFX application with a graphical user interface (GUI) based on the...

    I. User Interface Create a JavaFX application with a graphical user interface (GUI) based on the attached “GUI Mock-Up”. Write code to display each of the following screens in the GUI: A. A main screen, showing the following controls: • buttons for “Add”, “Modify”, “Delete”, “Search” for parts and products, and “Exit” • lists for parts and products • text boxes for searching for parts and products • title labels for parts, products, and the application title B. An add...

  • In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student...

    In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student information system. The application should allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow student to edit ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique...

  • The Northwind database created by Microsoft contains the sales data for a fictitious company called Northwind...

    The Northwind database created by Microsoft contains the sales data for a fictitious company called Northwind Traders, which imports and exports specialty foods from around the world. Here is the schema of the database: Products (ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued); Suppliers (SupplierID, CompanyName, ContactName , ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax, HomePage); Categories (CategoryID, CategoryName, Description, Picture); Orders (OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, ShipVia,  Freight, ShipName,ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry); Order_details (ID, OrderID,...

  • Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB....

    Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...

  • Write a program that reverses a text file by using a stack. The user interface must...

    Write a program that reverses a text file by using a stack. The user interface must consist of 2 list boxes and 3 buttons. The 3 buttons are: Read - reads the text file into list box 1. Reverse - reverses the items in list box 1 by pushing them onto stack 1, then popping them from stack 1 (in the reverse order) and adding them to list box 2. Write - writes the contents of list box 2 to...

  • Overview: Database management plays an integral role in nearly every area of business. Databases house customer, accoun...

    Overview: Database management plays an integral role in nearly every area of business. Databases house customer, accounting, and employee data, and these different data sets must all be efficiently managed in order to make the data accessible. Companies rely on database engineers to ensure that their records are accurate, updated, and tracked in real time. This course covers structured query language (SQL) and how it can be used to manage database schemas, manipulate data, and analyze data. For your final...

  • I NEED TO WRITE THE FOLLOWING QUERIES IN MYSQL (13)Next, grant to a user admin the read privileges on the complete descr...

    I NEED TO WRITE THE FOLLOWING QUERIES IN MYSQL (13)Next, grant to a user admin the read privileges on the complete descriptions of the customers who submitted no orders. For example, these are the customers who registered themselves and submitted no orders so far. The granted privilege cannot be propagated to the other users. 0.3 (14)Next, grant to a user admin the read privileges on information about the total number of orders submitted by each customer. Note, that some customers...

  • PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will...

    PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will guide you in starting the program in a methodical way. The program will display a window with GUI widgets that are associated with particular functions: Employee Payroll O X -- - - - - - - - - - - Show Payroll Find Employee by Name Highest Lowest Find Employee by Amount Write Output to Fie Cancel - -------- ------------- Notice that some of...

  • Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a...

    Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a queue. Then you are going to use the queue to store animals. 1. Write a LinkedQueue class that implements the QueueADT.java interface using links. 2. Textbook implementation uses a count variable to keep track of the elements in the queue. Don't use variable count in your implementation (points will be deducted if you use instance variable count). You may use a local integer variable...

  • database and sql problme THE QUESTIONS 3, 4,5 and 6 REFER TO THE RELATIONAL TABLES LISTED...

    database and sql problme THE QUESTIONS 3, 4,5 and 6 REFER TO THE RELATIONAL TABLES LISTED BELOW CREATE TABLE Department ( DECIMAL(5) VARCHAR(30) CHAR(5) DATE NOT NULL NOT NULL NOT NULL * Department number /*Department name * Department manager number */ /Manager start date DNumber DName Manager MSDate CONSTRAINT Department_PK PRIMARY KEY(DNumber) CONSTRAINT Department_CK UNIQUE(DName) CREATE TABLE DeptLocation DECIMAL(5) VARCHAR(50) NOT NULL NOT NULL DNumber * Department number */ * Department location */ Address CONSTRAINT DeptLocation_PK PRIMARY KEY(DNumber, Address) CONSTRAINT...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT