📄 exercise24_13.java
字号:
import java.awt.*;import javax.swing.*;public class Exercise24_13 extends javax.swing.JApplet { Exercise21_6PieChart pieChart1 = new Exercise21_6PieChart(); Exercise21_6BarChart barChart1 = new Exercise21_6BarChart(); Exercise21_6ChartModel chartModel1 = new Exercise21_6ChartModel(); /** Creates new form Exercise24_13 */ public Exercise24_13() { initComponents(); chartController1.setChartModel(chartModel1); pieChart1.setModel(chartModel1); barChart1.setModel(chartModel1); } /** 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. */ private void initComponents() {//GEN-BEGIN:initComponents jPanel1 = new javax.swing.JPanel(); jbtPieChart = new javax.swing.JButton(); jbtBarChart = new javax.swing.JButton(); chartController1 = new Exercise24_13ChartController(); jbtPieChart.setText("View Pie Chart"); jbtPieChart.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtPieChartActionPerformed(evt); } }); jPanel1.add(jbtPieChart); jbtBarChart.setText("View Bar Chart"); jbtBarChart.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtBarChartActionPerformed(evt); } }); jPanel1.add(jbtBarChart); getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH); getContentPane().add(chartController1, java.awt.BorderLayout.CENTER); }//GEN-END:initComponents private void jbtBarChartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtBarChartActionPerformed JFrame barChartFrame = new JFrame("View Bar Chart"); barChartFrame.getContentPane().add(barChart1); barChartFrame.setSize(200, 200); barChartFrame.setVisible(true); }//GEN-LAST:event_jbtBarChartActionPerformed private void jbtPieChartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtPieChartActionPerformed JFrame pieChartFrame = new JFrame("View Pie Chart"); pieChartFrame.getContentPane().add(pieChart1); pieChartFrame.setSize(200, 200); pieChartFrame.setVisible(true); }//GEN-LAST:event_jbtPieChartActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel jPanel1; private javax.swing.JButton jbtBarChart; private Exercise24_13ChartController chartController1; private javax.swing.JButton jbtPieChart; // End of variables declaration//GEN-END:variables public static void main(String[] args) { Exercise24_13 applet = new Exercise24_13(); JFrame frame = new JFrame(); //EXIT_ON_CLOSE == 3 frame.setDefaultCloseOperation(3); frame.setTitle("Exercise24_13"); frame.getContentPane().add(applet, java.awt.BorderLayout.CENTER); applet.init(); applet.start(); frame.setSize(400,320); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2); frame.setVisible(true); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -