Untitled
unknown
plain_text
4 years ago
2.3 kB
5
Indexable
import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.Ellipse2D; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; public class Facultate2 extends JFrame implements ActionListener { private JTextField nr1; private JTextField nr2; private JButton btn; private JPanel panel; private final int dist = 40; private int w = 0; private int h = 0; public Facultate2(){ panel = new JPanel(); panel.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(panel); panel.setLayout(null); setTitle("Facultate"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 500, 700); nr1 = new JTextField(""); nr1.setBounds(20, 100, 400, 30); panel.add(nr1); nr2 = new JTextField(""); nr2.setBounds(20, 120 + dist, 400, 30); panel.add(nr2); btn = new JButton("Draw"); btn.setBounds(20, 200, 400, 30); panel.add(btn); btn.addActionListener(this); this.setVisible(true); } public void paint(Graphics g){ Graphics2D g2 = (Graphics2D) g; g2.draw(new Ellipse2D.Double(20, 350, w, h)); } @Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == btn){ int w = Integer.parseInt(nr1.getText()); int h = Integer.parseInt(nr2.getText()); System.out.println(h + " " + w); if (h < 5 || h > 150 || w < 5 || w > 150) System.out.println("Bad values!"); if (h == w) { try { BufferedWriter out = new BufferedWriter(new FileWriter("out.txt", true)); out.write(h + " " + w); out.close(); } catch (IOException ioException) { ioException.printStackTrace(); } } repaint(); } } public static void main(String[] args) { Facultate2 f = new Facultate2(); } }
Editor is loading...