Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mc1try1;
- import javax.swing.*;
- import javax.swing.table.DefaultTableCellRenderer;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class MyResult extends javax.swing.JDialog {
- JTable tableB;
- JTextField Z0,Z1,Z2,Z3,Z4,Z5,Z6,Z7;
- JTextField lZ0,lZ1,lZ2,lZ3,lZ4,lZ5,lZ6,lZ7;
- MyResult(java.awt.Frame parent, Double B[][], double stateCURR, Double stan[]) {
- super(parent, true);
- initComponents(B,stateCURR,stan);
- this.setSize(600, 400);
- this.setLocationRelativeTo(null);
- this.setVisible(true);
- }
- ActionListener pressCLOSE = new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- };
- ActionListener pressOK = new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- dispose();
- }
- };
- private void initComponents(Double B[][], double stateCURR, Double stan[][]) {
- JLabel l2, l4;
- l2 = new JLabel("Матриця В:");
- l4 = new JLabel("Ймовірності перебування автомата у станах:");
- Box full = Box.createHorizontalBox();
- full.add(Box.createHorizontalStrut(50));
- Box box = Box.createVerticalBox();
- box.add(Box.createVerticalStrut(20));
- box.add(l2);
- box.add(Box.createVerticalStrut(5));
- box.add(createTableB(B));
- box.add(Box.createVerticalStrut(50));
- box.add(l4);
- box.add(Box.createVerticalStrut(5));
- JPanel outl = new JPanel(new FlowLayout(FlowLayout.CENTER,0,0));
- setZL();
- outl.add(lZ0); outl.add(lZ1);outl.add(lZ2);outl.add(lZ3);outl.add(lZ4);outl.add(lZ5);outl.add(lZ6);outl.add(lZ7);
- JPanel out = new JPanel(new FlowLayout(FlowLayout.CENTER,0,0));
- initialiseZ(stan);
- out.add(Z0); out.add(Z1);out.add(Z2);out.add(Z3);out.add(Z4);out.add(Z5);out.add(Z6);out.add(Z7);
- box.add(outl);
- box.add(out);
- box.add(Box.createVerticalStrut(20));
- box.add(new JLabel("Ймовірність появи на виході автомата вихідного сигнала, рівного 1: " + stateCURR));
- box.add(Box.createVerticalStrut(50));
- full.add(box);
- full.add(Box.createHorizontalStrut(50));
- setContentPane(full);
- }
- private JScrollPane createTableB(Double B[][]) {
- String[] columnNames = {
- "Z0", "Z1","Z2","Z3","Z4","Z5","Z6","Z7",
- };
- tableB = new JTable(B, columnNames);
- tableB.setModel(new javax.swing.table.DefaultTableModel(B, columnNames));
- tableB.setDefaultRenderer(tableB.getColumnClass(1), new DefaultTableCellRenderer() {
- public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
- super.setHorizontalAlignment(SwingConstants.CENTER);
- super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
- return this;
- }
- });
- tableB.getModel().addTableModelListener(tableB);
- JScrollPane scrollPane = new JScrollPane(tableB, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- scrollPane.setSize(20,30);
- return scrollPane;
- }
- private void initialiseZ(Double stan[][]) {
- int size = 3;
- Z0 = new JTextField(size);
- Z1 = new JTextField(size);
- Z2 = new JTextField(size);
- Z3 = new JTextField(size);
- Z4 = new JTextField(size);
- Z5 = new JTextField(size);
- Z6 = new JTextField(size);
- Z7 = new JTextField(size);
- Z0.setText("" + stan[0][0]);
- Z1.setText("" + stan[0][1]);
- Z2.setText("" + stan[0][2]);
- Z3.setText("" + stan[0][3]);
- Z4.setText("" + stan[0][4]);
- Z5.setText("" + stan[0][5]);
- Z6.setText("" + stan[0][6]);
- Z7.setText("" + stan[0][7]);
- }
- private void setZL() {
- int size = 3;
- lZ0 = new JTextField(size);
- lZ1 = new JTextField(size);
- lZ2 = new JTextField(size);
- lZ3 = new JTextField(size);
- lZ4 = new JTextField(size);
- lZ5 = new JTextField(size);
- lZ6 = new JTextField(size);
- lZ7 = new JTextField(size);
- lZ0.setText("Z0");
- lZ0.setEditable(false);
- lZ1.setText("Z1");
- lZ1.setEditable(false);
- lZ2.setText("Z2");
- lZ2.setEditable(false);
- lZ3.setText("Z3");
- lZ3.setEditable(false);
- lZ4.setText("Z4");
- lZ4.setEditable(false);
- lZ5.setText("Z5");
- lZ5.setEditable(false);
- lZ6.setText("Z6");
- lZ6.setEditable(false);
- lZ7.setText("Z7");
- lZ7.setEditable(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement