import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JPanel;
import javax.swing.UIManager;
public class Painting extends JApplet implements ActionListener {
public Font font = new Font("Dialog", Font.BOLD, 15);
public Font font2 = new Font("Dialog", Font.BOLD, 18);
public JButton jButton, jButton2;
public JFormattedTextField jFormattedTextField, jFormattedTextField2,
jFormattedTextField3, jFormattedTextField4;
public Hinertgrund cHintergrund;
public Runeins cRuneins;
public Runzwei cRunzwei;
int pPaint = 0;
int rectX, rectY, rectLength, rectWide;
public void init() {
getContentPane().setBackground(new Color(235, 240, 255));
getContentPane().setLayout(null);
getContentPane().setSize(248, 217);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception ex) {
System.err.println(ex);
}
jFormattedTextField = new JFormattedTextField();
jFormattedTextField.setHorizontalAlignment(JFormattedTextField.CENTER);
jFormattedTextField.setCaretPosition(0);
jFormattedTextField.setBounds(76, 361, 50, 30);
jFormattedTextField.setFont(font2);
jFormattedTextField.addActionListener(this);
jFormattedTextField.setEnabled(true);
jFormattedTextField.setEditable(true);
jFormattedTextField.setFocusable(true);
jFormattedTextField.setBackground(Color.white);
getContentPane().add(jFormattedTextField);
jFormattedTextField2 = new JFormattedTextField();
jFormattedTextField2.setHorizontalAlignment(JFormattedTextField.CENTER);
jFormattedTextField2.setCaretPosition(0);
jFormattedTextField2.setBounds(131, 361, 50, 30);
jFormattedTextField2.setFont(font2);
jFormattedTextField2.addActionListener(this);
jFormattedTextField2.setEnabled(true);
jFormattedTextField2.setEditable(true);
jFormattedTextField2.setFocusable(true);
jFormattedTextField2.setBackground(Color.white);
getContentPane().add(jFormattedTextField2);
jFormattedTextField3 = new JFormattedTextField();
jFormattedTextField3.setHorizontalAlignment(JFormattedTextField.CENTER);
jFormattedTextField3.setCaretPosition(0);
jFormattedTextField3.setBounds(186, 361, 50, 30);
jFormattedTextField3.setFont(font2);
jFormattedTextField3.addActionListener(this);
jFormattedTextField3.setEnabled(true);
jFormattedTextField3.setEditable(true);
jFormattedTextField3.setFocusable(true);
jFormattedTextField3.setBackground(Color.white);
getContentPane().add(jFormattedTextField3);
jFormattedTextField4 = new JFormattedTextField();
jFormattedTextField4.setHorizontalAlignment(JFormattedTextField.CENTER);
jFormattedTextField4.setCaretPosition(0);
jFormattedTextField4.setBounds(241, 361, 50, 30);
jFormattedTextField4.setFont(font2);
jFormattedTextField4.addActionListener(this);
jFormattedTextField4.setEnabled(true);
jFormattedTextField4.setEditable(true);
jFormattedTextField4.setFocusable(true);
jFormattedTextField4.setBackground(Color.white);
getContentPane().add(jFormattedTextField4);
ImageIcon icon = new ImageIcon(Painting.class
.getResource("drawRect.gif"));
jButton = new JButton("Paint", icon);
jButton.setFont(font);
jButton.setBounds(306, 336, 120, 25);
jButton.setBackground(new Color(255, 255, 255));
jButton.addActionListener(this);
getContentPane().add(jButton);
ImageIcon icon2 = new ImageIcon(Painting.class
.getResource("fillRect.gif"));
jButton2 = new JButton("Paint", icon2);
jButton2.setFont(font);
jButton2.setBounds(306, 364, 120, 25);
jButton2.setBackground(new Color(255, 255, 255));
jButton2.addActionListener(this);
getContentPane().add(jButton2);
cHintergrund = new Hinertgrund();
cHintergrund.setBounds(0, 0, 440, 330);
getContentPane().add(cHintergrund);
cRuneins = new Runeins();
cRunzwei = new Runzwei();
}
class Runeins {
public void run() {
rectX = Integer.parseInt(jFormattedTextField.getText());
rectY = Integer.parseInt(jFormattedTextField2.getText());
rectLength = Integer.parseInt(jFormattedTextField3.getText());
rectWide = Integer.parseInt(jFormattedTextField4.getText());
}
}
class Runzwei {
public void run() {
rectX = Integer.parseInt(jFormattedTextField.getText());
rectY = Integer.parseInt(jFormattedTextField2.getText());
rectLength = Integer.parseInt(jFormattedTextField3.getText());
rectWide = Integer.parseInt(jFormattedTextField4.getText());
}
}
class Hinertgrund extends JPanel {
public void paint(Graphics g) {
g.setColor(new Color(0, 0, 0));
g.fillRect(0, 0, 439, 329);
if (pPaint == 1) {
cRuneins.run();
g.setColor(new Color(255, 0, 0));
g.drawRect(rectX, rectY, rectLength, rectWide);
}
if (pPaint == 2) {
cRunzwei.run();
g.setColor(new Color(255, 0, 0));
g.fillRect(rectX, rectY, rectLength, rectWide);
}
}
}
public void actionPerformed(ActionEvent ae) {
Object source = ae.getSource();
if (source == jButton) {
pPaint = 1;
cHintergrund.repaint();
}
if (source == jButton2) {
pPaint = 2;
cHintergrund.repaint();
}
}
}