📄 test3dframe.java
字号:
/* * Test3DFrame.java * * Created on 2008年11月20日, 上午9:40 */package javatest3d;import com.sun.j3d.utils.applet.MainFrame;import com.sun.j3d.utils.universe.SimpleUniverse;import java.awt.BorderLayout;import java.awt.GraphicsConfiguration;import java.awt.HeadlessException;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.IOException;import javax.media.j3d.Canvas3D;import javax.swing.JFileChooser;import javax.swing.JFrame;/** * * @author Administrator */public class Test3DFrame extends javax.swing.JFrame { /** Creates new form Test3DFrame */ public Test3DFrame() { initComponents(); } /** 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. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jButton1 = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); jMenuItem2 = new javax.swing.JMenuItem(); jMenuItem3 = new javax.swing.JMenuItem(); jMenuItem4 = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 328, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 412, Short.MAX_VALUE) ); jButton1.setText("J3D"); jButton1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton1MouseClicked(evt); } }); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE) .addContainerGap()) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE) .addContainerGap()) ); jButton2.setText("J2D"); jButton3.setText("jButton3"); jButton3.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton3MouseClicked(evt); } }); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jMenu1.setText("File"); jMenuItem1.setText("New"); jMenu1.add(jMenuItem1); jMenuItem2.setText("Open"); jMenuItem2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jMenuItem2MouseClicked(evt); } }); jMenu1.add(jMenuItem2); jMenuItem3.setText("Save"); jMenu1.add(jMenuItem3); jMenuItem4.setText("Save As"); jMenu1.add(jMenuItem4); jMenuBar1.add(jMenu1); jMenu2.setText("Edit"); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(18, 18, 18) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(37, 37, 37) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton1) .addComponent(jButton2)) .addContainerGap()) .addComponent(jButton3))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(37, 37, 37) .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2) .addGap(122, 122, 122) .addComponent(jButton3)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponentsprivate void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked// TODO add your handling code here: getContentPane().setLayout(new BorderLayout()); GraphicsConfiguration config= SimpleUniverse.getPreferredConfiguration(); new MainFrame (new JTest3D(),300,300);// mf.setVisible(true);// MainFrame config=new MainFrame (new JTest3D(),300,300); Canvas3D canvas3D=new Canvas3D(config);// getContentPane().add("Center",canvas3D); jPanel1.add("Center",canvas3D);}//GEN-LAST:event_jButton1MouseClickedprivate JFileChooser fc;private File f; private int flag; private JFrame frm; private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked// TODO add your handling code here: //设置打开文件对话框的标题 fc.setDialogTitle("打开文件"); //这里显示打开文件的对话框 try{ flag=fc.showOpenDialog(frm); } catch(HeadlessException head){ System.out.println("打开文件出错!"); } //如果按下确定按钮,则获得该文件。 if(flag==JFileChooser.APPROVE_OPTION) { //获得该文件 f=fc.getSelectedFile(); try { FileReader fr=new FileReader(f); BufferedReader br=new BufferedReader(fr); String line=br.readLine(); StringBuffer ss=new StringBuffer(line); while(line!=null) { line=br.readLine(); ss.append("\r\n"+line); } String rr=new String(ss); StringBuffer rs=new StringBuffer(rr.length()-4); for(int i=0;i<rr.length()-4;i++) rs.append(rr.charAt(i)); //programe.setText(rs.toString());//将打开的文件写入到文本框programe中 } catch (IOException ee) {} } }//GEN-LAST:event_jButton3MouseClickedprivate void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed// TODO add your handling code here:}//GEN-LAST:event_jButton3ActionPerformedprivate void jMenuItem2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem2MouseClicked// TODO add your handling code here: //设置打开文件对话框的标题 fc.setDialogTitle("打开文件"); //这里显示打开文件的对话框 try{ flag=fc.showOpenDialog(frm); } catch(HeadlessException head){ System.out.println("打开文件出错!"); } //如果按下确定按钮,则获得该文件。 if(flag==JFileChooser.APPROVE_OPTION) { //获得该文件 f=fc.getSelectedFile(); try { FileReader fr=new FileReader(f); BufferedReader br=new BufferedReader(fr); String line=br.readLine(); StringBuffer ss=new StringBuffer(line); while(line!=null) { line=br.readLine(); ss.append("\r\n"+line); } String rr=new String(ss); StringBuffer rs=new StringBuffer(rr.length()-4); for(int i=0;i<rr.length()-4;i++) rs.append(rr.charAt(i)); //programe.setText(rs.toString());//将打开的文件写入到文本框programe中 } catch (IOException ee) {} } }//GEN-LAST:event_jMenuItem2MouseClicked /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Test3DFrame().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; private javax.swing.JMenuItem jMenuItem4; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextArea1; // End of variables declaration//GEN-END:variables}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -