List of usage examples for javax.swing BorderFactory createTitledBorder
public static TitledBorder createTitledBorder(Border border)
From source file:io.github.jeremgamer.editor.panels.MusicFrame.java
public MusicFrame(JFrame frame, final GeneralSave gs) { ArrayList<BufferedImage> icons = new ArrayList<BufferedImage>(); try {//from w ww . j a va 2s . com icons.add(ImageIO.read(ImageGetter.class.getResource("icon16.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon32.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon64.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon128.png"))); } catch (IOException e1) { e1.printStackTrace(); } this.setIconImages((List<? extends Image>) icons); this.setTitle("Musique"); this.setSize(new Dimension(300, 225)); this.addWindowListener(new WindowListener() { @Override public void windowActivated(WindowEvent event) { } @Override public void windowClosed(WindowEvent event) { } @Override public void windowClosing(WindowEvent event) { try { gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd")); } catch (IOException e) { e.printStackTrace(); } if (clip != null) { clip.stop(); clip.close(); try { audioStream.close(); } catch (IOException e) { e.printStackTrace(); } } } @Override public void windowDeactivated(WindowEvent event) { } @Override public void windowDeiconified(WindowEvent event) { } @Override public void windowIconified(WindowEvent event) { } @Override public void windowOpened(WindowEvent event) { } }); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS)); this.setModal(true); this.setLocationRelativeTo(frame); JPanel properties = new JPanel(); properties.setBorder(BorderFactory.createTitledBorder("Lecture")); ButtonGroup bg = new ButtonGroup(); bg.add(one); bg.add(loop); one.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JRadioButton rb = (JRadioButton) event.getSource(); if (rb.isSelected()) { gs.set("music.reading", 0); try { gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd")); } catch (IOException e) { e.printStackTrace(); } if (clip != null) { if (clip.isRunning()) clip.loop(0); } } } }); loop.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JRadioButton rb = (JRadioButton) event.getSource(); if (rb.isSelected()) { gs.set("music.reading", 1); try { gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd")); } catch (IOException e) { e.printStackTrace(); } if (clip != null) { if (clip.isRunning()) clip.loop(Clip.LOOP_CONTINUOUSLY); } } } }); properties.add(one); properties.add(loop); if (gs.getInt("music.reading") == 0) { one.setSelected(true); } else { loop.setSelected(true); } volume.setMaximum(100); volume.setMinimum(0); volume.setValue(30); volume.setPaintTicks(true); volume.setPaintLabels(true); volume.setMinorTickSpacing(10); volume.setMajorTickSpacing(20); volume.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent event) { JSlider slider = (JSlider) event.getSource(); double value = slider.getValue(); gain = value / 100; dB = (float) (Math.log(gain) / Math.log(10.0) * 20.0); if (clip != null) gainControl.setValue(dB); gs.set("music.volume", (int) value); } }); volume.setValue(gs.getInt("music.volume")); properties.add(volume); properties.setPreferredSize(new Dimension(300, 125)); content.add(properties); JPanel browsePanel = new JPanel(); browsePanel.setBorder(BorderFactory.createTitledBorder("")); JButton browse = new JButton("Parcourir..."); if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) { preview.setEnabled(false); browse.setText(""); try { browse.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } } browse.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JButton button = (JButton) event.getSource(); if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) { if (clip != null) { clip.stop(); clip.close(); try { audioStream.close(); } catch (IOException e) { e.printStackTrace(); } } name.setText(""); preview.setEnabled(false); button.setText("Parcourir..."); button.setIcon(null); new File("projects/" + Editor.getProjectName() + "/music.wav").delete(); gs.set("music.name", ""); } else { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Audio (WAV)", "wav"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyMusic(new File(path)); button.setText(""); try { button.setIcon( new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } gs.set("music.name", new File(path).getName()); try { gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd")); } catch (IOException e) { e.printStackTrace(); } name.setText(new File(path).getName()); preview.setEnabled(true); } } } }); if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) { preview.setEnabled(true); } else { preview.setEnabled(false); } preview.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JToggleButton tb = (JToggleButton) event.getSource(); if (tb.isSelected()) { try { audioStream = AudioSystem.getAudioInputStream( new File("projects/" + Editor.getProjectName() + "/music.wav")); format = audioStream.getFormat(); info = new DataLine.Info(Clip.class, format); clip = (Clip) AudioSystem.getLine(info); clip.open(audioStream); clip.start(); gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(dB); if (loop.isSelected()) { clip.loop(Clip.LOOP_CONTINUOUSLY); } else { clip.loop(0); } clip.addLineListener(new LineListener() { @Override public void update(LineEvent event) { Clip clip = (Clip) event.getSource(); if (!clip.isRunning()) { preview.setSelected(false); clip.stop(); clip.close(); try { audioStream.close(); } catch (IOException e) { e.printStackTrace(); } } } }); } catch (Exception exc) { exc.printStackTrace(); } } else { clip.stop(); clip.close(); try { audioStream.close(); } catch (IOException e) { e.printStackTrace(); } } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BorderLayout()); buttons.add(browse, BorderLayout.WEST); buttons.add(preview, BorderLayout.EAST); browsePanel.setLayout(new BorderLayout()); browsePanel.add(buttons, BorderLayout.NORTH); browsePanel.add(name, BorderLayout.SOUTH); name.setPreferredSize(new Dimension(280, 25)); name.setText(gs.getString("music.name")); content.add(browsePanel); this.setContentPane(content); this.setVisible(true); }
From source file:net.vanosten.dings.swing.SummaryView.java
private void initializeChartPropertiesPanel() { chartPropertiesP = new JPanel(); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); chartPropertiesP.setLayout(gbl);/* ww w .j a v a 2 s . co m*/ TitledBorder title; title = BorderFactory.createTitledBorder("Chart Properties"); chartPropertiesP.setBorder(title); JLabel typeL = new JLabel("Chart Type:"); typeL.setDisplayedMnemonic("C".charAt(0)); typeL.setLabelFor(chartTypeCB); JLabel emptyL = new JLabel(); Insets vghg = new Insets(DingsSwingConstants.SP_V_G, DingsSwingConstants.SP_H_G, 0, 0); //----type gbc.gridwidth = 1; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.LINE_END; gbc.insets = vghg; gbl.setConstraints(typeL, gbc); chartPropertiesP.add(typeL); //---- gbc.gridx = 1; gbc.anchor = GridBagConstraints.LINE_START; gbl.setConstraints(chartTypeCB, gbc); chartPropertiesP.add(chartTypeCB); //---- gbc.gridx = 2; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; gbl.setConstraints(emptyL, gbc); chartPropertiesP.add(emptyL); //----chosen gbc.gridx = 1; gbc.gridy = 1; gbc.weightx = 0.0; gbc.fill = GridBagConstraints.NONE; gbl.setConstraints(chosenCB, gbc); chartPropertiesP.add(chosenCB); }
From source file:fr.duminy.components.swing.form.JFormPane.java
/** * Generic constructor for a form./*from w w w .ja v a 2s.c om*/ * * @param formBuilder The builder to use for constructing the {@link Form}. * @param title The title of the dialog. * @param mode The mode to use for the form. */ public JFormPane(FormBuilder<B> formBuilder, String title, Mode mode) { super(new BorderLayout()); this.title = title; this.mode = mode; form = formBuilder.buildForm(); add(form.asComponent(), BorderLayout.CENTER); buttonsPanel = buildButtonsPanel(); add(buttonsPanel, BorderLayout.SOUTH); setBorder(BorderFactory.createTitledBorder(title)); setName(getDefaultPanelName(formBuilder.getBeanClass())); }
From source file:eu.delving.sip.frames.OutputFrame.java
private JPanel createOutputPanel() { final JPanel p = new JPanel(new BorderLayout()); p.setBorder(BorderFactory.createTitledBorder("Output record")); outputArea = new JTextArea(sipModel.getRecordCompileModel().getOutputDocument()); outputArea.setLineWrap(true);//from w ww. j a va 2 s. c o m outputArea.setFont(MONOSPACED); outputArea.setWrapStyleWord(true); outputArea.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent documentEvent) { try { String first = documentEvent.getDocument().getText(0, 1); final boolean error = first.startsWith("#"); setError(outputArea, error); sipModel.exec(new Swing() { @Override public void run() { outputArea.setCaretPosition(0); } }); } catch (BadLocationException e) { // who cares } } @Override public void removeUpdate(DocumentEvent documentEvent) { } @Override public void changedUpdate(DocumentEvent documentEvent) { } }); outputArea.getInputMap().put(KeystrokeHelper.DOWN, "next"); outputArea.getInputMap().put(KeystrokeHelper.RIGHT, "next"); outputArea.getInputMap().put(KeystrokeHelper.UP, "prev"); outputArea.getInputMap().put(KeystrokeHelper.LEFT, "prev"); outputArea.getActionMap().put("next", new NextAction()); outputArea.getActionMap().put("prev", new PrevAction()); searchField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { found.clear(); foundSelected = 0; String xml = outputArea.getText().toLowerCase(); String sought = searchField.getText().toLowerCase(); if (!sought.isEmpty()) { int start = 0; while (found.size() < 30) { int pos = xml.indexOf(sought, start); if (pos < 0) break; found.add(pos); start = pos + sought.length(); } } selectFound(); } }); JPanel sp = new JPanel(); JLabel label = new JLabel("Search:", JLabel.RIGHT); label.setLabelFor(searchField); sp.add(label); sp.add(searchField); sp.add(new JLabel("Press ENTER, then use arrow keys")); p.add(scrollVH(outputArea), BorderLayout.CENTER); p.add(sp, BorderLayout.SOUTH); return p; }
From source file:components.RootLayeredPaneDemo.java
private JPanel createControlPanel() { onTop = new JCheckBox("Top Position in Layer"); onTop.setSelected(true);// w w w . j a v a 2 s .c o m onTop.setActionCommand(ON_TOP_COMMAND); onTop.addActionListener(this); layerList = new JComboBox(layerStrings); layerList.setSelectedIndex(INITIAL_DUKE_LAYER_INDEX); layerList.setActionCommand(LAYER_COMMAND); layerList.addActionListener(this); JPanel controls = new JPanel(); controls.add(layerList); controls.add(onTop); controls.setBorder(BorderFactory.createTitledBorder("Choose Duke's Layer and Position")); return controls; }
From source file:LayeredPaneDemo.java
private JPanel createControlPanel() { onTop = new JCheckBox("Top Position in Layer"); onTop.setSelected(true);//from w ww .j a v a2 s.com onTop.setActionCommand(ON_TOP_COMMAND); onTop.addActionListener(this); layerList = new JComboBox(layerStrings); layerList.setSelectedIndex(2); // cyan layer layerList.setActionCommand(LAYER_COMMAND); layerList.addActionListener(this); JPanel controls = new JPanel(); controls.add(layerList); controls.add(onTop); controls.setBorder(BorderFactory.createTitledBorder("Choose Duke's Layer and Position")); return controls; }
From source file:TextSamplerDemo.java
public TextSamplerDemo() { setLayout(new BorderLayout()); //Create a regular text field. JTextField textField = new JTextField(10); textField.setActionCommand(textFieldString); textField.addActionListener(this); //Create a password field. JPasswordField passwordField = new JPasswordField(10); passwordField.setActionCommand(passwordFieldString); passwordField.addActionListener(this); //Create a formatted text field. JFormattedTextField ftf = new JFormattedTextField(java.util.Calendar.getInstance().getTime()); ftf.setActionCommand(textFieldString); ftf.addActionListener(this); //Create some labels for the fields. JLabel textFieldLabel = new JLabel(textFieldString + ": "); textFieldLabel.setLabelFor(textField); JLabel passwordFieldLabel = new JLabel(passwordFieldString + ": "); passwordFieldLabel.setLabelFor(passwordField); JLabel ftfLabel = new JLabel(ftfString + ": "); ftfLabel.setLabelFor(ftf);/*ww w . ja va2s. c om*/ //Create a label to put messages during an action event. actionLabel = new JLabel("Type text and then Enter in a field."); actionLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); //Lay out the text controls and the labels. JPanel textControlsPane = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); textControlsPane.setLayout(gridbag); JLabel[] labels = { textFieldLabel, passwordFieldLabel, ftfLabel }; JTextField[] textFields = { textField, passwordField, ftf }; addLabelTextRows(labels, textFields, gridbag, textControlsPane); c.gridwidth = GridBagConstraints.REMAINDER; //last c.anchor = GridBagConstraints.WEST; c.weightx = 1.0; textControlsPane.add(actionLabel, c); textControlsPane.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Text Fields"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); //Create a text area. JTextArea textArea = new JTextArea("This is an editable JTextArea. " + "A text area is a \"plain\" text component, " + "which means that although it can display text " + "in any font, all of the text is in the same font."); textArea.setFont(new Font("Serif", Font.ITALIC, 16)); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); JScrollPane areaScrollPane = new JScrollPane(textArea); areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); areaScrollPane.setPreferredSize(new Dimension(250, 250)); areaScrollPane.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Plain Text"), BorderFactory.createEmptyBorder(5, 5, 5, 5)), areaScrollPane.getBorder())); //Create an editor pane. JEditorPane editorPane = createEditorPane(); JScrollPane editorScrollPane = new JScrollPane(editorPane); editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorScrollPane.setPreferredSize(new Dimension(250, 145)); editorScrollPane.setMinimumSize(new Dimension(10, 10)); //Create a text pane. JTextPane textPane = createTextPane(); JScrollPane paneScrollPane = new JScrollPane(textPane); paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); paneScrollPane.setPreferredSize(new Dimension(250, 155)); paneScrollPane.setMinimumSize(new Dimension(10, 10)); //Put the editor pane and the text pane in a split pane. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, editorScrollPane, paneScrollPane); splitPane.setOneTouchExpandable(true); splitPane.setResizeWeight(0.5); JPanel rightPane = new JPanel(new GridLayout(1, 0)); rightPane.add(splitPane); rightPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Styled Text"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); //Put everything together. JPanel leftPane = new JPanel(new BorderLayout()); leftPane.add(textControlsPane, BorderLayout.PAGE_START); leftPane.add(areaScrollPane, BorderLayout.CENTER); add(leftPane, BorderLayout.LINE_START); add(rightPane, BorderLayout.LINE_END); }
From source file:ExtendedDnDDemo.java
private JPanel createTable() { DefaultTableModel model = new DefaultTableModel(); model.addColumn("Column 0"); model.addColumn("Column 1"); model.addColumn("Column 2"); model.addColumn("Column 3"); model.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" }); model.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" }); model.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" }); model.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" }); JTable table = new JTable(model); table.getTableHeader().setReorderingAllowed(false); table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); JScrollPane scrollPane = new JScrollPane(table); scrollPane.setPreferredSize(new Dimension(400, 100)); table.setDragEnabled(true);// www.j a v a 2s.c o m table.setTransferHandler(new TableTransferHandler()); JPanel panel = new JPanel(new BorderLayout()); panel.add(scrollPane, BorderLayout.CENTER); panel.setBorder(BorderFactory.createTitledBorder("Table")); return panel; }
From source file:com.google.code.facebook.graph.sna.applet.VertexLabelAsShapeDemo.java
/** * create an instance of a simple graph with basic controls *///from ww w . ja v a 2s .c o m public VertexLabelAsShapeDemo() { // create a simple graph for the demo graph = TestGraphs.getOneComponentGraph(); layout = new FRLayout<String, Number>(graph); Dimension preferredSize = new Dimension(400, 400); final VisualizationModel<String, Number> visualizationModel = new DefaultVisualizationModel<String, Number>( layout, preferredSize); vv = new VisualizationViewer<String, Number>(visualizationModel, preferredSize); // this class will provide both label drawing and vertex shapes VertexLabelAsShapeRenderer<String, Number> vlasr = new VertexLabelAsShapeRenderer<String, Number>( vv.getRenderContext()); // customize the render context vv.getRenderContext().setVertexLabelTransformer( // this chains together Transformers so that the html tags // are prepended to the toString method output new ChainedTransformer<String, String>( new Transformer[] { new ToStringLabeller<String>(), new Transformer<String, String>() { public String transform(String input) { return "<html><center>Vertex<p>" + input; } } })); vv.getRenderContext().setVertexShapeTransformer(vlasr); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.red)); vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.yellow)); vv.getRenderContext().setEdgeStrokeTransformer(new ConstantTransformer(new BasicStroke(2.5f))); // customize the renderer vv.getRenderer() .setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.gray, Color.white, true)); vv.getRenderer().setVertexLabelRenderer(vlasr); vv.setBackground(Color.black); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<String>()); final DefaultModalGraphMouse<String, Number> graphMouse = new DefaultModalGraphMouse<String, Number>(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JPanel controls = new JPanel(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); zoomControls.add(plus); zoomControls.add(minus); controls.add(zoomControls); controls.add(modeBox); content.add(controls, BorderLayout.SOUTH); }
From source file:simulation.AureoZauleckAnsLab2.java
/** * *///from w w w . j av a2 s . c o m public AureoZauleckAnsLab2() { // TODO code application logic here Scanner sc = new Scanner(System.in); String choice_s = ""; int choice = 0; do { DisplayMenu(); choice_s = sc.next(); String title = ""; Scanner s = new Scanner(System.in); //test input if (IsNumber(choice_s)) { choice = Convert(choice_s); } else { do { System.out.println("Please enter a number only."); choice_s = sc.next(); } while (!IsNumber(choice_s)); choice = Convert(choice_s); } if (choice == 1) { System.out.println("*** CATEGORICAL ***"); System.out.println(); System.out.println("TITLE(title of data set)"); //sc = new Scanner(System.in); title = s.nextLine(); System.out.println("this is the title: " + title); ArrayList a = new ArrayList<>(); ArrayList<Double> percentages = new ArrayList<>(); ArrayList<ArrayList> all; a = GetData(); Collections.sort(a); all = Stratified(a); System.out.println("GROUPED DATA: " + all); System.out.println("size " + all.size()); double percent = 0.0, sum = 0.0; for (int i = 0; i < all.size(); i++) { ArrayList inner = new ArrayList<>(); inner = all.get(i); //System.out.println(inner); int inner_n = inner.size(); percent = GetPercentage(N, inner_n); percentages.add(percent); sum += percent; System.out.println("" + inner.get(0) + "\t" + " " + percent); } System.out.println("\t" + "total " + Math.ceil(sum)); System.out.println("all = " + all); JFrame frame = new JFrame(); //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(); table.setModel(new DefaultTableModel((int) (all.size() + 2), 2)); table.setValueAt("VALUE LABELS", 0, 0); table.setValueAt("PERCENTAGE", 0, 1); table.setValueAt("TOTAL = 100%", (int) (all.size() + 1), 1); for (int i = 0; i < all.size(); i++) { table.setValueAt(all.get(i).get(0), i + 1, 0); table.setValueAt(new DecimalFormat("#.##").format(percentages.get(i)), i + 1, 1); } JScrollPane scrollPane = new JScrollPane(table); scrollPane.setBorder(BorderFactory.createTitledBorder(title)); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); int type = 0, testT = 0; String typeTest = ""; do { System.out.println("GENERATE GRAPH?"); System.out.println("[1] YES"); System.out.println("[2] NO"); System.out.println(); System.out.println("Please pick a number from the choices above."); typeTest = sc.next(); if (IsNumber(typeTest)) { testT = Convert(typeTest); } else { do { System.out.println("Please enter a number only."); typeTest = sc.next(); } while (!IsNumber(typeTest)); testT = Convert(typeTest); } type = testT; } while (type < 1 || type > 2); if (type == 1) { DefaultPieDataset dataset = new DefaultPieDataset(); for (int i = 0; i < all.size(); i++) { dataset.setValue( all.get(i).get(0).toString() + " = " + new DecimalFormat("#.##").format(percentages.get(i)) + "%", percentages.get(i)); } JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data true, // include legend true, false); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(560, 367)); JFrame l = new JFrame(); l.setContentPane(chartPanel); l.setSize(400, 400); l.setVisible(true); } else { //do nothing? } int type2 = 0, testT2 = 0; String typeTest2 = ""; do { System.out.println("REDISPLAY TABLE?"); System.out.println("[1] YES"); System.out.println("[2] NO"); System.out.println(); System.out.println("Please pick a number from the choices above."); typeTest2 = sc.next(); if (IsNumber(typeTest2)) { testT2 = Convert(typeTest2); } else { do { System.out.println("Please enter a number only."); typeTest2 = sc.next(); } while (!IsNumber(typeTest2)); testT2 = Convert(typeTest2); } type2 = testT2; } while (type2 < 1 || type2 > 2); if (type2 == 1) { DisplayTable(all, percentages, title); } else { //do nothing? } } else if (choice == 2) { System.out.println("*** NUMERICAL ***"); System.out.println(); System.out.println("TITLE(title of data set)"); title = s.nextLine(); System.out.println("this is the title " + title); ArrayList<Double> a = new ArrayList<>(); //ArrayList<ArrayList> all; //a = GetData2(); double[] arr = { 70, 36, 43, 69, 82, 48, 34, 62, 35, 15, 59, 139, 46, 37, 42, 30, 55, 56, 36, 82, 38, 89, 54, 25, 35, 24, 22, 9, 55, 19 }; /* double[] arr = {112, 100, 127,120,134,118,105,110,109,112, 110, 118, 117, 116, 118, 122, 114, 114, 105, 109, 107, 112, 114, 115, 118, 117, 118, 122, 106, 110, 116, 108, 110, 121, 113, 120, 119, 111, 104, 111, 120, 113, 120, 117, 105, 110, 118, 112, 114, 114}; */ N = arr.length; double t = 0.0; for (int i = 0; i < N; i++) { a.add(arr[i]); } Collections.sort(a); System.out.println("sorted a " + a); double min = (double) a.get(0); double max = (double) a.get(N - 1); System.out.println("Min" + min); System.out.println("Max" + max); double k = Math.ceil(1 + 3.322 * Math.log10(N)); System.out.println("K " + k); double range = GetRange(min, max); System.out.println("Range " + range); double width = Math.ceil(range / k); //todo, i ceiling sa 1st decimal point System.out.println("Width " + width); ArrayList<Double> cl = new ArrayList<>(); cl.add(min); double rest; for (int i = 1; i < k; i++) { cl.add(min += width); } ArrayList<Double> cl2 = new ArrayList<>(); double cl2min = cl.get(1) - 1; cl2.add(cl2min); for (int i = 1; i < k; i++) { cl2.add(cl2min += width); } System.out.println("cl 1 " + cl); System.out.println("cl 2 " + cl2); ArrayList<Double> tlcl = new ArrayList<>(); double tlclmin = cl.get(0) - Multiplier(cl.get(0)); tlcl.add(tlclmin); for (int i = 1; i < k; i++) { tlcl.add(tlclmin += width); } ArrayList<Double> tucl = new ArrayList<>(); double tuclmin = cl2.get(0) + Multiplier(cl2.get(0)); tucl.add(tuclmin); for (int i = 1; i < k; i++) { tucl.add(tuclmin += width); } System.out.println("tlcl 1 " + tlcl); System.out.println("tucl 2 " + tucl); System.out.println("N " + N); ArrayList<Double> midList = new ArrayList<>(); double mid = (cl.get(0) + cl2.get(0)) / 2; midList.add(mid); for (int i = 1; i < k; i++) { midList.add((tlcl.get(i) + tucl.get(i)) / 2); } for (int i = 0; i < k; i++) { System.out.println((tlcl.get(i) + tucl.get(i)) / 2); } System.out.println("mid" + midList); ArrayList<ArrayList<Double>> freq = new ArrayList<>(); double ctr = 0.0; for (int j = 0; j < k; j++) { for (int i = 0; i < N; i++) { if ((a.get(i) >= tlcl.get(j)) && (a.get(i) <= tucl.get(j))) { freq.add(new ArrayList<Double>()); freq.get(j).add(a.get(i)); } } } ArrayList<Double> freqSize = new ArrayList<>(); double size = 0.0; for (int i = 0; i < k; i++) { size = (double) freq.get(i).size(); freqSize.add(size); } ArrayList<Double> freqPercent = new ArrayList<>(); for (int i = 0; i < k; i++) { freqPercent.add(freqSize.get(i) / N * 100); } ArrayList<Double> cfs = new ArrayList<>(); double cf = freqSize.get(0); cfs.add(cf); for (int i = 1; i < k; i++) { cf = freqSize.get(i) + cfs.get(i - 1); cfs.add(cf); } double sum = 0.0; for (int i = 1; i < cfs.size(); i++) { sum += cfs.get(i); } ArrayList<Double> cps = new ArrayList<>(); double cp = 0.0; for (int i = 0; i < k; i++) { cp = (cfs.get(i) / N) * 100; cps.add(cp); } System.out.println("T o t a l: " + sum); System.out.println(cfs); System.out.println(cps); System.out.println("frequency list " + freq); System.out.println("frequency sizes " + freqSize); System.out.println("frequency percentages " + freqPercent); System.out.println(); System.out.println(title); System.out.println("CLASS LIMITS" + "\t" + "T CLASS LIMITS" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT" + "\t" + "CF" + "\t" + "CP"); for (int i = 0; i < k; i++) { System.out.println(cl.get(i) + " - " + cl2.get(i) + "\t" + tlcl.get(i) + " - " + tucl.get(i) + "\t" + midList.get(i) + "\t" + freq.get(i).size() + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t" + new DecimalFormat("#.##").format(cps.get(i))); } //2 System.out.println("CLASS LIMITS" + "\t" + "T C L" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT" + "\t" + "CF" + "\t" + "CP"); for (int i = 0; i < k; i++) { System.out.println(">=" + cl.get(i) + "\t\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size() + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t" + new DecimalFormat("#.##").format(cps.get(i))); } //3 System.out.println("CLASS LIMITS" + "\t" + "T C L" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT" + "\t" + "CF" + "\t" + "CP"); for (int i = 0; i < k; i++) { System.out.println("<=" + cl2.get(i) + "\t\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size() + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t" + new DecimalFormat("#.##").format(cps.get(i))); } System.out.println("CLASS LIMITS" + "\t" + "T CLASS LIMITS" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT" + "\t" + "CF" + "\t" + "CP"); for (int i = 0; i < k; i++) { System.out.println(">=" + cl.get(i) + " and <=" + cl2.get(i) + "\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size() + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t" + new DecimalFormat("#.##").format(cps.get(i))); } DisplayTables(k, cl, cl2, tlcl, tucl, midList, freq, freqPercent, cfs, cps, title); int type = 0, testT = 0; String typeTest = ""; do { do { System.out.println(); System.out.println("GENERATE GRAPH?"); System.out.println("[1] YES"); System.out.println("[2] NO"); System.out.println(); System.out.println("Please pick a number from the choices above."); typeTest = sc.next(); if (IsNumber(typeTest)) { testT = Convert(typeTest); } else { do { System.out.println("Please enter a number only."); typeTest = sc.next(); } while (!IsNumber(typeTest)); testT = Convert(typeTest); } type = testT; } while (type < 1 || type > 2); if (type == 1) { int bins = (int) k; System.out.println(); System.out.println("You may input a label for your X axis:"); String x = ""; x = s.nextLine(); createHistogram(a, bins, title, x); int type2 = 0, testT2 = 0; String typeTest2 = ""; do { System.out.println(); System.out.println("REDISPLAY TABLE?"); System.out.println("[1] YES"); System.out.println("[2] NO"); System.out.println(); System.out.println("Please pick a number from the choices above."); typeTest2 = sc.next(); if (IsNumber(typeTest2)) { testT2 = Convert(typeTest2); } else { do { System.out.println("Please enter a number only."); typeTest2 = sc.next(); } while (!IsNumber(typeTest2)); testT2 = Convert(typeTest2); } type2 = testT2; } while ((type2 < 1 || type2 > 2) && type != 2); if (type2 == 1) { DisplayTables(k, cl, cl2, tlcl, tucl, midList, freq, freqPercent, cfs, cps, title); } else { //do nothing? } } } while (type != 2); } else if (choice == 3) { System.out.println("*** QUIT ***"); } } while (choice != 3); System.out.println("Thank you for your time."); s = new Simulation(); }