Вывод данный из JTextField на картинку - Java
Формулировка задачи:
Добрый день коллеги!
Пишу сюда впервые так что прошу снисхождения за ошибки).
Создаю программу учета и печати документов для отдела, в данный момент сделал форму для заполнения пользователем но появилась трудность вывода заполненых данных на картинке с формой документа. Подскажите пожалуйста где ошибка, желательно с примерами. Заранее спасибо.
public class DocsRSO { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new MyFrame ("Служба учета документации РСО"); } }); } } class MyFrame extends JFrame{ private static final long serialVersionUID = 1L; MyFrame(String string){ super ("Программа учета документации"); int width = 1024; int hegth = 768; setBounds(400,300, width,hegth); setLayout(null); setDefaultCloseOperation(EXIT_ON_CLOSE); new MyMenuBar(this); setVisible(true); } } package Examples; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; class MyMenuBar extends JMenuBar implements ActionListener{ /** * */ private static final long serialVersionUID = 1L; MyMenuBar (MyFrame frame){ super(); JMenu Document = new JMenu("Справки"); JMenuItem CrDoc = new JMenuItem("Создать справку"); JMenuItem RedDoc = new JMenuItem("Редактировать справку"); JMenuItem DelDoc = new JMenuItem("Удалить справку"); Document.add(CrDoc); Document.add(RedDoc); Document.add(DelDoc); CrDoc.addActionListener(this); add(Document); setBounds(1,1, frame.getWidth()-1, frame.getHeight()/10); frame.add(this); } public void actionPerformed(ActionEvent cd){ if (cd.getActionCommand().equals("Создать справку")) { new CreateForm("Создание формы справки").setVisible(true);; } } } package Examples; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.util.Arrays; import java.util.Vector; public class CreateForm extends JFrame implements ActionListener { /** * */ private static final long serialVersionUID = 1L; SpringLayout sl = new SpringLayout(); JPanel panel = new JPanel(sl); JLabel jlFormSp; // форма справки JButton searchJB; JComboBox jtFormSp; // форма справки JLabel jlNumberSp; // номер справки JTextField jtNumberSp; // номер справки JCheckBox jCBox; //автомат номера справки JLabel jlDateSp; // дата справки String[] days = {"01","02","03","04","05","06","07","08","09","10", "11","12","13","14","15","16","17","18","19","20", "21","22","23","24","25","26","27","28","29","30","31"}; String [] months = {"января", "февраля", "марта", "апреля","мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"}; String[] forms = {"1","2","3"}; JComboBox<?> daysJCB; // список дней JComboBox<?> monthsJCB; // список месяцев JTextField yearsJTF; // поле год JTextField secondNameJTF; // Фамилия JLabel secondNameJL; // Фамилия JTextField nameJTF; // Имя JLabel nameJL; //Имя JTextField fatherNameJTF; // Отчество JLabel fatherNameJL; // Отчество JLabel numDopJL; // Номер допуска JTextField numDopJTF; // Номер допуска JLabel whatDateJL; JComboBox<?> whatDateDayJCB; JComboBox<?> whatDateMonthJCB; JTextField whatDateYearJTF; JLabel whatDateAcceptJL; JComboBox<?> whatDateAcceptDayJCB; JComboBox<?> whatDateAcceptMonthJCB; JTextField whatDateAcceptYearJTF; JLabel whatFinDateJL; JComboBox<?> whatFinDateDayJCB; JComboBox<?> whatFinDateMonthJCB; JTextField whatFinDateYearJTF; @SuppressWarnings("unchecked") public CreateForm(String string) { setSize(1000, 800); setLocation(500, 200); panel.setSize(100, 50); panel.add(jlFormSp = new JLabel("Форма справки")); panel.add(jlNumberSp = new JLabel("Номер справки")); panel.add(jtFormSp = new JComboBox (forms)); // форма справки panel.add(jtNumberSp = new JTextField (4)); // номер справки panel.add(jCBox = new JCheckBox("Автоматически")); jCBox.setEnabled(true); // автомат номера справки panel.add(jlDateSp = new JLabel("Дата создания справки")); panel.add(daysJCB = new JComboBox<Object>(days)); // дни даты panel.add(monthsJCB = new JComboBox<Object>(months)); // месяцы даты panel.add(yearsJTF = new JTextField(4)); panel.add(secondNameJTF = new JTextField(20)); panel.add(secondNameJL = new JLabel("Фамилия")); panel.add(nameJTF = new JTextField(20)); panel.add(nameJL = new JLabel("Имя")); panel.add(fatherNameJTF = new JTextField(20)); panel.add(fatherNameJL = new JLabel("Отчество")); panel.add(searchJB = new JButton("Создать форму")); panel.add(numDopJL = new JLabel("Номер допуска")); panel.add(numDopJTF = new JTextField(10)); panel.add(whatDateJL = new JLabel("от какого числа")); panel.add(whatDateDayJCB = new JComboBox<Object>(days)); panel.add(whatDateMonthJCB = new JComboBox<Object>(months)); panel.add(whatDateYearJTF = new JTextField(5)); panel.add(whatDateAcceptJL = new JLabel("Дата утверждения")); panel.add(whatDateAcceptDayJCB = new JComboBox(days)); panel.add(whatDateAcceptMonthJCB = new JComboBox<Object>(months)); panel.add(whatDateAcceptYearJTF = new JTextField(5)); panel.add(whatFinDateJL = new JLabel("Дата окончания справки")); panel.add(whatFinDateDayJCB = new JComboBox<Object>(days)); panel.add(whatFinDateMonthJCB = new JComboBox<Object>(months)); panel.add(whatFinDateYearJTF = new JTextField(5)); sl.putConstraint(SpringLayout.WEST, jlFormSp, 15, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, jlFormSp, 15, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, jtFormSp, 130, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, jtFormSp, 15, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, jlNumberSp, 50, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, jlNumberSp, 15, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, jtNumberSp, 50, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, jtNumberSp, 130, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, jCBox, 90, SpringLayout.WEST,panel); sl.putConstraint(SpringLayout.WEST, jCBox, 350, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, jlDateSp, 90, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, jlDateSp, 15, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, daysJCB, 90, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, daysJCB, 160, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, monthsJCB, 90, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, monthsJCB, 210, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, yearsJTF, 90, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, yearsJTF, 300, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, secondNameJL, 15, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, secondNameJL, 130, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, secondNameJTF, 130, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, secondNameJTF, 130, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, nameJL, 15, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, nameJL, 170, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, nameJTF, 170, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, nameJTF, 130, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, fatherNameJL, 210, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, fatherNameJL, 15, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, fatherNameJTF, 210, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, fatherNameJTF, 130, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, numDopJL, 250, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, numDopJL, 15, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, numDopJTF, 250, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, numDopJTF, 130, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, whatDateJL, 250, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, whatDateJL, 260, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, whatDateDayJCB, 250, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, whatDateDayJCB, 360, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, whatDateMonthJCB, 250, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, whatDateMonthJCB, 410, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, whatDateYearJTF, 500, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, whatDateYearJTF, 250, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, whatDateAcceptJL, 245, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, whatDateAcceptJL, 300, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, whatDateAcceptDayJCB, 300, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, whatDateAcceptDayJCB,360, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, whatDateAcceptMonthJCB, 300, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, whatDateAcceptMonthJCB, 410, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, whatDateAcceptYearJTF, 300, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, whatDateAcceptYearJTF, 500, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, whatFinDateJL, 350, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, whatFinDateJL, 15, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, whatFinDateDayJCB, 350, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, whatFinDateDayJCB, 200, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, whatFinDateMonthJCB, 350, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, whatFinDateMonthJCB, 250, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, whatFinDateYearJTF, 350, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, whatFinDateYearJTF, 340, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.NORTH, searchJB, 400, SpringLayout.WEST, panel); sl.putConstraint(SpringLayout.WEST, searchJB, 25, SpringLayout.WEST, panel); searchJB.addActionListener(this); setContentPane(panel); setVisible(true); } public void actionPerformed(ActionEvent sjb) { if (sjb.getActionCommand().equals("Создать форму")){ new InputLetterForm().setVisible(true); //new EnterData(); } } } package Examples; import java.awt.FlowLayout; import java.awt.Font; import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridLayout; import java.awt.Image; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.awt.event.*; import javax.imageio.ImageIO; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JLayeredPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.SpringLayout; import javax.swing.text.BadLocationException; public class InputLetterForm extends JFrame { public Image spravkaDva; SpringLayout inSL = new SpringLayout(); JLayeredPane panel = getLayeredPane(); SpringLayout sl = new SpringLayout(); InputLetterForm years; // поле год InputLetterForm secondName; // Фамилия JLabel secondNameJL; // Фами InputLetterForm fatherName; // Отчество JLabel fatherNameJL; // Отчество JLabel numDopJL; // Номер допуска InputLetterForm numDop; // Номер допуска JLabel whatDateJL; JComboBox<?> whatDateDayJCB; JComboBox<?> whatDateMonthJCB; InputLetterForm whatDateYear; InputLetterForm whatDateAcceptYear; InputLetterForm whatFinDateYear; InputLetterForm days; String name; InputLetterForm(){ super ("Форма справки"); spravkaDva = getToolkit().getImage("D:/Distr/workspace/Lesson0/src/Spravka2.jpg"); spravkaDva = spravkaDva.getScaledInstance(1174, 893, Image.SCALE_AREA_AVERAGING); int width = 1174; int hegth = 1000; setBounds(400,100, width,hegth); setLayout(null); name = new String(); //setContentPane(panel); setVisible(true); } public void addpanelData(CreateForm obj){ name = String.valueOf(obj.nameJTF.getText()); obj.nameJTF.setText(name); } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D)g; g.drawImage(spravkaDva, 0, 0, this); g2.setFont(new Font("Times new Romain", Font.PLAIN, 64)); g2.drawString(name, 100, 200); } }
Решение задачи: «Вывод данный из JTextField на картинку»
textual
Листинг программы
setVisible(true);
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д