A00094635_Ass6 - WordPress – www.wordpress.com

hundredcarriageΛογισμικό & κατασκευή λογ/κού

3 Νοε 2013 (πριν από 3 χρόνια και 8 μήνες)

76 εμφανίσεις

Name:

Tian JingQuan

S
tudent number
:

A00094635

C
lass
:

Bsc in software Design in Web Devlopment in Year 3

A
ssignment number
:
Lab_Exercise_
6



TASK1

1.codes


import javax.swing.JButton;

import javax.swing.JFrame;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import javax.swing.JLabel;

import java.awt.event.ActionListener;

import javax.swing.JComboBox;

import javax.swing.JTextField;


public class Main extends JFrame implem
ents ActionListener{


private JButton theButton1 = new JButton("Button 1");


private JButton theButton2 = new JButton("Button 2");


private JButton theButton3 = new JButton("Button 3");


private JButton theButton4 = new JButton("Button 4");


private
JLabel label1=new JLabel("");




public Main(String aStr) {


super(aStr);


getContentPane().setLayout(new GridLayout(3,2));



getContentPane().add(theButton1);


getContentPane().add(theButton2);


getContentPane().add(theButton3)
;


getContentPane().add(theButton4);


getContentPane().add(label1);



theButton1.addActionListener(this);


theButton2.addActionListener(this);


theButton3.addActionListener(this);


theButton4.addActionListener(this);



se
tSize(350,200);


setVisible(true);


}



public void actionPerformed(ActionEvent event)


{


if(event.getSource() == theButton1)


label1.setText(theButton1.getText());


else if(event.getSource() ==
theButton2)


label1.setText(theButton2.getText());


else if (event.getSource() == theButton3)


label1.setText(theButton3.getText());


else if(event.getSource() == theButton4)


label1.setTex
t(theButton4.getText());




}


public static void main(String[] args) {


new Main("Assignment 6");


}


}


2.screen shot











TASK2

1.codes


import javax.swing.JButton;

import
javax.swing.JFrame;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import javax.swing.JLabel;

import java.awt.event.ActionListener;

import javax.swing.JComboBox;

import javax.swing.JTextField;


public class Main extends JFrame implements Ac
tionListener{


private JLabel label1=new JLabel("Enter value to convert:");


private JTextField tf=new JTextField();


private JComboBox cb=new JComboBox();


private JButton theButton1 = new JButton("convert");




private JLabel label2=new JLabel("");




public Main(String aStr) {


super(aStr);


getContentPane().setLayout(new GridLayout(3,2));



getContentPane().add(label1);


getContentPane().add(tf);


getContentPane().add(cb);


getContentPane().add(theButton1);



getContentPane().add(label2);




cb.addItem("Meter to Feet");


cb.addItem("Feet to Meter");



theButton1.addActionListener(this);



setSize(350,200);


setVisible(true);


}



public void actionPerformed(ActionEvent

event)


{


if(event.getSource() == theButton1)


{


double res=0;


if(cb.getSelectedIndex()==0) res=Double.parseDouble(tf.getText())*3.28;


else res=Double.parseDouble(tf.getText())*
0.3;


label2.setText("Result is: "+res);


}


}


public static void main(String[] args) {


new Main("Assignment 6");


}


}



2.screen shot







TASK3


1.
codes


import
javax.swing.JFrame;

import javax.swing.JButton;

import javax.swing.JCheckBox;

import javax.swing.JPanel;

import java.awt.event.*;

import javax.swing.JLabel;



public class Main extends JFrame implements ActionListener {


private JButton theButton = new JBu
tton("Caculate Grade");


private JCheckBox theCB80 = new JCheckBox("Score>80",false);


private JCheckBox theCB70 = new JCheckBox("Score>70",false);


private JCheckBox theCB50 = new JCheckBox("Score>50",false);


private JCheckBox theCB40 = new

JCheckBox("Score>40",false);


private JCheckBox theCBloss = new JCheckBox("Score<40",false);


private JPanel thePanel = new JPanel();


private JLabel label1=new JLabel("");


private JLabel label2=new JLabel("Grade is A");


priv
ate JLabel label3=new JLabel("Grade is B");


private JLabel label4=new JLabel("Grade is C");


private JLabel label5=new JLabel("Grade is D");


private JLabel label6=new JLabel("Grade is fail");



public Main (String str) {



super(str);




thePanel.add(theCB80);



thePanel.add(theCB70);


thePanel.add(theCB50);



thePanel.add(theCB40);


thePanel.add(theCBloss);


thePanel.add(label1);



thePanel.add(theButton);



//thePanel.setBackgro
und(java.awt.Color.cyan);




getContentPane().add(thePanel);



theButton.addActionListener(this);





setSize(100,250);




setVisible(true);


}


public void actionPerformed(ActionEvent e){



boolean A = theCB80.isSelected();



boolean B = theCB70.isSelected();


boolean C = theCB50.isSelected();


boolean D = theCB40.isSelected();


boolean fail = theCBloss.isSelected();



if (A == true){


theCB80.set
Selected(false);





theCB70.setSelected(false);





theCB50.setSelected(false);


theCB40.setSelected(false);





theCBloss.setSelected(false);


label1.setText(
label2.getText());




}



else if (B == true){


theCB70.setSelected(false);





theCB80.setSelected(false);





theCB50.setSelected(false);


theCB40.setSelected(false);





theCBloss.setSelected(false);


label1.setText(label3.getText());




}


else if (C == true){


theCB70.setSelected(false);





theCB80.setSelected(false);





theCB
50.setSelected(false);


theCB40.setSelected(false);





theCBloss.setSelected(false);


label1.setText(label4.getText());




}


else if (D == true){



theCB70.setSelected(false);





theCB80.setSelected(false);





theCB50.setSelected(false);


theCB40.setSelected(false);





theCBloss.setSelected(false);


label1
.setText(label5.getText());




}


else if (fail == true){


theCB70.setSelected(false);





theCB80.setSelected(false);





theCB50.setSelected(false);


theCB40.setSelected(false);





theCBloss.setSelected(false);


label1.setText(label6.getText());




}


}


public static void main(String[] args){



new Main("Ass6");


}



}


2.screen shot