answersLogoWhite

0

package shorts.task;

public class shorts extends javax.swing.JFrame {

/** Creates new form shorts */

public shorts() {

initComponents();

}

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jLabel1 = new javax.swing.JLabel();

back = new javax.swing.JButton();

clear = new javax.swing.JButton();

submit = new javax.swing.JButton();

next = new javax.swing.JButton();

OrderNo = new javax.swing.JTextField();

size = new javax.swing.JTextField();

NoShorts = new javax.swing.JTextField();

TotalShorts = new javax.swing.JTextField();

cost = new javax.swing.JTextField();

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

jLabel4 = new javax.swing.JLabel();

jLabel5 = new javax.swing.JLabel();

jLabel6 = new javax.swing.JLabel();

CostButton = new javax.swing.JButton();

shortsTotal = new javax.swing.JButton();

print = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));

jLabel1.setText("shorts order form");

back.setText("back");

back.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

backActionPerformed(evt);

}

});

clear.setText("clear");

clear.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

clearActionPerformed(evt);

}

});

submit.setText("submit");

submit.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

submitActionPerformed(evt);

}

});

next.setText("next");

next.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

nextActionPerformed(evt);

}

});

OrderNo.setText("order no");

OrderNo.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

OrderNoActionPerformed(evt);

}

});

size.setText("size");

size.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

sizeActionPerformed(evt);

}

});

NoShorts.setText("no of shorts");

NoShorts.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

NoShortsActionPerformed(evt);

}

});

TotalShorts.setText("total no of shorts");

cost.setText("cost");

cost.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

costActionPerformed(evt);

}

});

jLabel2.setText("order no");

jLabel3.setText("size");

jLabel4.setText("no of shorts");

jLabel5.setText("total no of shorts");

jLabel6.setText("cost");

CostButton.setText("cost");

CostButton.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

CostButtonActionPerformed(evt);

}

});

shortsTotal.setText("NoShortsTotal");

shortsTotal.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

shortsTotalActionPerformed(evt);

}

});

print.setText("print all items");

print.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

printActionPerformed(evt);

}

});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(73, 73, 73)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 373, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel2)

.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel4)

.addComponent(jLabel5)

.addComponent(jLabel6))

.addGap(18, 18, 18))

.addComponent(back))

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(OrderNo, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)

.addComponent(size, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)

.addComponent(NoShorts, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)

.addComponent(TotalShorts, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)

.addComponent(cost, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)

.addGroup(layout.createSequentialGroup()

.addComponent(clear)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(print)

.addGroup(layout.createSequentialGroup()

.addComponent(submit)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(next)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addComponent(CostButton)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addComponent(shortsTotal)))))))

.addContainerGap(52, javax.swing.GroupLayout.PREFERRED_SIZE))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(OrderNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(size, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(NoShorts, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel4))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(TotalShorts, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel5))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(cost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel6))

.addGap(36, 36, 36)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(clear)

.addComponent(back)

.addComponent(submit)

.addComponent(next)

.addComponent(CostButton)

.addComponent(shortsTotal))

.addGap(43, 43, 43)

.addComponent(print)

.addContainerGap(65, Short.MAX_VALUE))

);

pack();

}// </editor-fold>

private void backActionPerformed(java.awt.event.ActionEvent evt) {

counter --;

OrderNo.setText(Integer.toString(counter));

size.setText((shortSize[counter]));

NoShorts.setText(Integer.toString(noItem[counter]));

}

private void OrderNoActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

}

private void costActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

}

private void sizeActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

}

private void clearActionPerformed(java.awt.event.ActionEvent evt) {

OrderNo.setText("0");

cost.setText("0");

NoShorts.setText("0");

size.setText(" ");

TotalShorts.setText("0");

}

private void nextActionPerformed(java.awt.event.ActionEvent evt) {

counter ++;

OrderNo.setText(Integer.toString(counter));

size.setText((shortSize[counter]));

NoShorts.setText("0");

}

private void submitActionPerformed(java.awt.event.ActionEvent evt) {

noItem[counter] = Integer.parseInt(NoShorts.getText());

shortSize[counter] = size.getText();

}

private void NoShortsActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

}

private void CostButtonActionPerformed(java.awt.event.ActionEvent evt) {

cost.setText(String.valueOf(cost(Integer.parseInt(NoShorts.getText()))));

}

private void shortsTotalActionPerformed(java.awt.event.ActionEvent evt) {

int sum = 0;

for (int i = 0; i <noItem.length; i++){

sum += noItem[i];

TotalShorts.setText(Integer.toString(sum));

}

}

private void printActionPerformed(java.awt.event.ActionEvent evt) {

int S = 0;

int M = 0;

int L = 0;

for (int i = 0; i<noItem.length;i++){

if (shortSize[i]. equals("S")){

S = S +noItem[i];

}

if (shortSize[i]. equals("M")){

M = M +noItem[i];

}

if (shortSize[i]. equals("L")){

L = L +noItem[i];

}

}

System.out.println(S);

System.out.println(M);

System.out.println(L);

}

static double cost(int items){

double total = 0;

if (items <2){

total = 40* items;}

if (items ==2){

total = 40* items*.95;}

if (items >2){

total = 40* items*.90;}

return total;

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

for (int i = 0; i < shortSize.length; i++){

shortSize[i] = "";

}

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new shorts().setVisible(true);

}

});

}

static String shortSize[] = new String [40];

int noItem[] = new int[40];

int counter = 0;

// Variables declaration - do not modify

private javax.swing.JButton CostButton;

private javax.swing.JTextField NoShorts;

private javax.swing.JTextField OrderNo;

private javax.swing.JTextField TotalShorts;

private javax.swing.JButton back;

private javax.swing.JButton clear;

private javax.swing.JTextField cost;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JLabel jLabel5;

private javax.swing.JLabel jLabel6;

private javax.swing.JButton next;

private javax.swing.JButton print;

private javax.swing.JButton shortsTotal;

private javax.swing.JTextField size;

private javax.swing.JButton submit;

// End of variables declaration

}

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
ReneRene
Change my mind. I dare you.
Chat with Rene

Add your answer:

Earn +20 pts
Q: How do you make jumpers?
Write your answer...
Submit
Still have questions?
magnify glass
imp