?? controls.java
字號:
// Made by Yasir 05CS86 and Group.
import parport.ParallelPort;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;
class Controls extends JFrame implements ActionListener, ItemListener {
private Image Icon;
private JCheckBox switch1,switch2,switch3;
private JButton btnAbout, btnSThanx;
private JLabel windowlabel, address;
int data = 0, times = 0, newAdd = 0;
ParallelPort lpt1 = new ParallelPort(0x378);
public Controls(){
Toolkit toolkit = this.getToolkit();
Dimension d=toolkit.getScreenSize();
Icon = toolkit.getImage("Images/Icon.jpg");
this.setBounds(d.width/4,d.height/4,400,300);
this.setIconImage(Icon);
setTitle("Parallel Port Interface");
lpt1.write(8);
addComponents();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setResizable(false);
this.setVisible(true);
}
// Add components to Container.
public void addComponents(){
Container c = this.getContentPane();
c.setLayout(null);
windowlabel= new JLabel("SWITCHES CONTROL PANEL");
windowlabel.setFont(new Font("Verdana",Font.BOLD,20));
windowlabel.setBounds(23,8,350,50);
c.add(windowlabel);
address = new JLabel ("- Parallel port address is currently defined at 0x378h -");
address.setFont(new Font("Verdana", Font.ITALIC, 12));
address.setBounds(23,50,350,20);
c.add(address);
switch1 = new JCheckBox("Switch 1");
switch1.setBounds(20,100,100,30);
switch1.addItemListener(this);
c.add(switch1);
switch2 = new JCheckBox("Switch 2");
switch2.addItemListener(this);
switch2.setBounds(150,100,100,30);
c.add(switch2);
switch3 = new JCheckBox("Switch 3");
switch3.addItemListener(this);
switch3.setBounds(280,100,100,30);
c.add(switch3);
btnAbout = new JButton("About Group");
btnAbout.addActionListener(this);
btnAbout.setBounds(35,210,150,25);
c.add(btnAbout);
btnSThanx = new JButton("Special Thanx");
btnSThanx.addActionListener(this);
btnSThanx.setBounds(210,210,150,25);
c.add(btnSThanx);
}
public void itemStateChanged(ItemEvent iE){
JCheckBox cB = (JCheckBox)iE.getItem();
int state = iE.getStateChange();
try{
if (state == ItemEvent.SELECTED){
/* if (btnB.getText() == "About Group"){
System.out.println("Yes it it");
}*/
if (cB.getText() == "Switch 1"){
data = data + 1;
times = 1;
}
if (cB.getText() == "Switch 2"){
data = data + 2;
times = 2;
}
if (cB.getText() == "Switch 3"){
data = data + 4;
times = 3;
}
for (byte i = 1; i <= times; i++){
Thread.sleep(200);
lpt1.write((data + 128));
Thread.sleep(50);
lpt1.write(data);
}
}
lpt1.write(data);
times = 0;
if (state == ItemEvent.DESELECTED){
if (cB.getText() == "Switch 1"){
data = data - 1;
times = 1;
}
if (cB.getText() == "Switch 2"){
data = data - 2;
times = 2;
}
if (cB.getText() == "Switch 3"){
data = data - 4;
times = 3;
}
lpt1.write((data + 128));
Thread.sleep(500);
lpt1.write(data);
for (byte i = 1; i <= times; i++){
Thread.sleep(200);
lpt1.write(data+128);
Thread.sleep(50);
lpt1.write(data);
}
lpt1.write(data);
}
if (data == 0)
lpt1.write(8);
}
catch(Exception x){};
}
public void actionPerformed(ActionEvent aE){
if (aE.getSource() == btnAbout)
JOptionPane.showMessageDialog(null, "My Group:\n\n- Yasir Karim Qureshi (05CS86)" +
"\n- 05CS05\n- 05CS12\n- 05CS42\n- 05CS66\n\n Our Group is Best!!!");
if (aE.getSource() == btnSThanx)
JOptionPane.showMessageDialog(null, "Special Thanx to\n\n 'Sir Manzoor Hashmani'\n" +
"And 'Sir Shahzad Nizamani'\n" +
"\n who made us able to achieve this approach!");
}
public static void main(String[] args){
new Controls();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -