Phân tích thiết kế

Một phần của tài liệu Ứng dụng các phần mềm để tạo phòng thí nghiệm ảo phục vụ giảng dạy (Trang 71 - 83)

CHƯƠNG 3. PHÁT TRIỂN ỨNG DỤNG CHO PHÒNG THÍ NGHIỆM ẢO VỚI NGÔN NGỮ LẬP TRÌNH JAVA

3.2. Phân tích thiết kế

Hệ thống không thiết kế cơ sở dữ liệu để lưu trữ, chỉ dùng kỹ thuật lập trình để tích hợp các chương trình phần mềm có sẵn. chương trình được tạo bởi các hàm sau:

package virLabDemo;

import java.awt.Component;

import java.io.BufferedInputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import javax.swing.JOptionPane;

67 import javax.swing.ProgressMonitorInputStream;

public class Antenna extends javax.swing.JFrame { String sysPath;

/**

* Creates new form Antenna */

public Antenna() { initComponents();

sysPath = System.getProperty("user.dir");

} /**

* This method is called from within the constructor to initialize the form.

* WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor.

*/

// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN- BEGIN:initComponents

private void initComponents() {

btnYenka = new javax.swing.JButton();

btnGeogebra = new javax.swing.JButton();

btnVlab = new javax.swing.JButton();

btnCro = new javax.swing.JButton();

jPanel1 = new javax.swing.JPanel();

jLabel1 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setTitle("VirLabDemo 1.0");

setBackground(new java.awt.Color(52, 73, 94));

setResizable(false);

btnYenka.setBackground(new java.awt.Color(243, 156, 18));

68

btnYenka.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N btnYenka.setForeground(new java.awt.Color(255, 255, 255));

btnYenka.setIcon(new

javax.swing.ImageIcon(getClass().getResource("/images/yenka.png"))); // NOI18N btnYenka.setText("<html> <center>" + "Phòng thí nghiệm" + "<br>" +

"TỔNG HỢP" +"<br>"+"với"+"<br>" + "<font size=\"5\"

color=\"red\">YENKA</font>" + "</center> </html>");

btnYenka.setToolTipText("Phòng thí nghiệm với Yenka");

btnYenka.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

btnYenka.setIconTextGap(6);

btnYenka.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnYenkaActionPerformed(evt);

} });

btnGeogebra.setBackground(new java.awt.Color(0, 153, 153));

btnGeogebra.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N btnGeogebra.setForeground(new java.awt.Color(255, 255, 255));

btnGeogebra.setIcon(new

javax.swing.ImageIcon(getClass().getResource("/images/mathematica.png"))); //

NOI18N

btnGeogebra.setText("<html> <center>" + "Phòng thí nghiệm" + "<br>" +

"TOÁN HỌC" +"<br>"+"với"+"<br>" + "<font size=\"5\"

color=\"orange\">GEOGEBRA<br> </font>" + "</center> </html>");

btnGeogebra.setToolTipText("");

btnGeogebra.setActionCommand("");

btnGeogebra.setCursor(new

java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

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

69

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

} });

btnVlab.setBackground(new java.awt.Color(142, 68, 173));

btnVlab.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N btnVlab.setForeground(new java.awt.Color(255, 255, 255));

btnVlab.setIcon(new

javax.swing.ImageIcon(getClass().getResource("/images/microscope.png"))); //

NOI18N

btnVlab.setText("<html> <center>" + "Phòng thí nghiệm" +

"<br>"+""+"<br>" + "<font size=\"5\"

color=\"red\">VIRTUAL<br>MICROCOPE</font>" + "</center> </html>");

btnVlab.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

btnVlab.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnVlabActionPerformed(evt);

} });

btnCro.setBackground(new java.awt.Color(41, 128, 185));

btnCro.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N btnCro.setForeground(new java.awt.Color(255, 255, 255));

btnCro.setIcon(new

javax.swing.ImageIcon(getClass().getResource("/images/chemistry_laboratory.png"

))); // NOI18N

btnCro.setText("<html> <center>" + "Phòng thí nghiệm" + "<br>" + "HÓA HỌC" +"<br>"+"với"+"<br>" + "<font size=\"5\"

color=\"red\">CROCODILE<br></font>" + "</center> </html>");

btnCro.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

70

btnCro.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCroActionPerformed(evt);

} });

jPanel1.setBackground(new java.awt.Color(44, 62, 80));

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel1.setForeground(new java.awt.Color(255, 255, 255));

jLabel1.setText("PHÒNG THÍ NGHIỆM ẢO");

org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);

jPanel1.setLayout(jPanel1Layout);

jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING,

jPanel1Layout.createSequentialGroup()

.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.add(jLabel1)

.add(162, 162, 162)) );

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING,

jPanel1Layout.createSequentialGroup()

.addContainerGap(26, Short.MAX_VALUE) .add(jLabel1)

.add(20, 20, 20)) );

71

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup()

.addContainerGap()

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)

.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.add(layout.createSequentialGroup()

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)

.add(btnVlab, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.add(btnGeogebra,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 312,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)

add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(btnCro,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 312,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(org.jdesktop.layout.GroupLayout.TRAILING, btnYenka,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 312,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))

72

.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING,

layout.createSequentialGroup()

.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)

add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(btnGeogebra,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 154,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(btnCro, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 154, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)

add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(btnVlab, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.add(btnYenka, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 154, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.addContainerGap()) );

73 pack();

}// </editor-fold>//GEN-END:initComponents

private void btnYenkaActionPerformed(java.awt.event.ActionEvent evt) {//GEN- FIRST:event_btnYenkaActionPerformed

// TODO add your handling code here:

try {

String yenkaPath = sysPath + "\\Yenka\\Software\\Yenka.exe";

Process p = Runtime.getRuntime().exec(yenkaPath);

// p.waitFor();

} catch (Exception e) {

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

}

}//GEN-LAST:event_btnYenkaActionPerformed

private void btnGeogebraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGeogebraActionPerformed

try {

String geoPath = sysPath + "\\GeoGebra_4.2.60.0\\GeoGebra.exe";

Process p = Runtime.getRuntime().exec(geoPath);

} catch (Exception e) {

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

}

}//GEN-LAST:event_btnGeogebraActionPerformed

private void btnVlabActionPerformed(java.awt.event.ActionEvent evt) {//GEN- FIRST:event_btnVlabActionPerformed

try {

String vlabPath = sysPath + "\\Virtual_Lab\\VirtualLab.exe";

Process p = Runtime.getRuntime().exec(vlabPath);

74 } catch (Exception e) {

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

}

}//GEN-LAST:event_btnVlabActionPerformed

private void btnCroActionPerformed(java.awt.event.ActionEvent evt) {//GEN- FIRST:event_btnCroActionPerformed

try {

String croPath = sysPath +

"\\Crocodile_Chemistry_6.05\\Crocodile_Chemis_6.05.exe";

Process p = Runtime.getRuntime().exec(croPath);

} catch (Exception e) {

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

}

}//GEN-LAST:event_btnCroActionPerformed /**

* @param args the command line arguments */

public static void main(String args[]) { /* Set the Nimbus look and feel */

//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

* For details see

http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */

try {

javax.swing.UIManager.LookAndFeelInfo[] installedLookAndFeels = javax.swing.UIManager.getInstalledLookAndFeels();

75

for (int idx = 0; idx < installedLookAndFeels.length; idx++) { if ("Nimbus".equals(installedLookAndFeels[idx].getName())) {

javax.swing.UIManager.setLookAndFeel(installedLookAndFeels[idx].getClassNam e());

break;

} }

} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(Antenna.class.getName()).log(java.util.logging.

Level.SEVERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(Antenna.class.getName()).log(java.util.logging.

Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(Antenna.class.getName()).log(java.util.logging.

Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(Antenna.class.getName()).log(java.util.logging.

Level.SEVERE, null, ex);

}

//</editor-fold>

/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() { public void run() {

76 new Antenna().setVisible(true);

} });

}

private Component parentComponent;

public void copyFile() { File srcFolder = new File(

"D:\\testcopy");

File destFolder = new File(

"D:\\testcopy2");

if (!srcFolder.exists()) {

JOptionPane.showMessageDialog(null, "Thư mục không tồn tại.");

System.exit(0);

} else { try {

copyFolder(srcFolder, destFolder);

} catch (IOException e) { e.printStackTrace();

System.exit(0);

} }

JOptionPane.showMessageDialog(null, "Back up request has been completed");

}

public void copyFolder(File src, File dest) throws IOException { if (src.isDirectory()) {

if (!dest.exists()) { dest.mkdir();

}

77 String files[] = src.list();

for (String file : files) {

File srcFile = new File(src, file);

File destFile = new File(dest, file);

copyFolder(srcFile, destFile);

} } else {

InputStream in = new BufferedInputStream(

new ProgressMonitorInputStream(parentComponent, "Reading "

+ src, new FileInputStream(src)));

OutputStream out = new FileOutputStream(dest);

byte[] buffer = new byte[1024];

int length;

while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length);

}

in.close();

out.close();

} }

// Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnCro;

private javax.swing.JButton btnGeogebra;

private javax.swing.JButton btnVlab;

private javax.swing.JButton btnYenka;

private javax.swing.JLabel jLabel1;

private javax.swing.JPanel jPanel1;

// End of variables declaration//GEN-END:variables }

Một phần của tài liệu Ứng dụng các phần mềm để tạo phòng thí nghiệm ảo phục vụ giảng dạy (Trang 71 - 83)

Tải bản đầy đủ (PDF)

(86 trang)