Друзья, пишу текстовый редактор. Нашел в литературе составные компоненты программы, но собрать их вместе не получается. Если будет возможность, соберите части воедино, рlease!!! (заранее извиняюсь, код на Java)
| Код | JEditorPane jEditorPane1 = new JEditorPane(); JLabel jL1 = new JLabel ("Шрифт"); JLabel jL2 = new JLabel ("Размер"); JLabel jL3 = new JLabel ("Стиль"); JLabel jL4 = new JLabel ("Цвет"); JComboBox jComboBox1=new JComboBox(); JComboBox jComboBox2=new JComboBox(); JComboBox jComboBox3=new JComboBox(); JList jList1 = new JList(); String fontName="Arial"; int size = 14, style = 0; Font textFont = new Font (fontName, style, size); Создание списков. jComboBox1.addItem("Arial"); jComboBox1.addItem("Time New Roman"); jComboBox1.setSelectedItem("Arial"); jComboBox2.addItem("8"); jComboBox2.addItem("10"); jComboBox2.addItem("12"); jComboBox2.addItem("14"); jComboBox2.addItem("16"); jComboBox2.addItem("20"); jComboBox2.addItem("36"); jComboBox2.setSelectedItem("14"); jComboBox3.addItem("none"); jComboBox3.addItem("bold"); jComboBox3.addItem("italic"); jComboBox3.addItem("bold & italic"); jComboBox3.setSelectedItem("none"); String[] colors = new String[] {"red","green","blue","yellow","violet", "light blue","black"}; jList1.setListData(colors); jList1.setSelectedIndex(0); jEditorPane1.setForeground(new Color (255,0,0)); jEditorPane1.setFont(textFont); Обработчики событий списков public void jComboBox1_actionPerformed(ActionEvent e) { fontName = (String)jComboBox1.getSelectedItem(); textFont = new Font (fontName,style,size); jEditorPane1.setFont(textFont); } public void jComboBox2_actionPerformed(ActionEvent e ) { size = Integer.parseInt((String)jComboBox2.getSelectedItem()); textFont = new Font (fontName,style,size); jEditorPane1.setFont(textFont); } public void jComboBox3_actionPerformed(ActionEvent e) { style = jComboBox3.getSelectedIndex(); textFont = new Font (fontName, style, size); jEditorPane1.setFont(textFont); Обработчик события valueChanged public void jList1_valueChanged(ListSelectionEvent e) { switch (jList1.getSelectedIndex()) { case 0: jEditorPane1.setForeground(new Color(255,0,0)); break; case 1: jEditorPane1.setForeground(new Color(0,255,0)); break; case 2: jEditorPane1.setForeground(new Color(0,0,255)); break; case 3: jEditorPane1.setForeground(new Color(255,255,0)); break; case 4: jEditorPane1.setForeground(new Color(255,0,255)); break; case 5: jEditorPane1.setForeground(new Color(0,255,255)); break; case 6: jEditorPane1.setForeground(new Color(0,0,0)); } }
|
|