Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Spiel;
- import java.awt.Color;
- import java.awt.Container;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JColorChooser;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JSlider;
- import javax.swing.JTextArea;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- public class MyPanel extends JPanel {
- public Connection con;
- public MyPanel() {
- this.show();
- }
- DrawArea drawArea;
- private Color oldColor = Color.BLACK;
- private JButton Faben,Löschen,radirgummi;
- private static JTextArea log;
- private JScrollPane anzeige;
- private JSlider Big;
- public static JFrame frame;
- ActionListener actionListener = new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == Faben) {
- JColorChooser colorChooser = new JColorChooser();
- Color c = colorChooser.showDialog(null, "color", oldColor);
- drawArea.setColor(c);
- oldColor = c;
- }else if (e.getSource() == Löschen) {
- drawArea.clear();
- con.serversendMessage("clear");
- }else if (e.getSource() == radirgummi) {
- drawArea.setColor(new Color(255, 255, 255));
- }
- }
- };
- public void show() {
- // create main frame
- frame = new JFrame("Malen");
- Container content = frame.getContentPane();
- //Set buttons Action listener
- //
- addLog(frame);
- //Faben Button
- Faben = new JButton("Faben");
- Faben.setBounds(520, 410, 200, 30);
- Faben.addActionListener(actionListener);
- frame.add(Faben);
- //Löschen
- Löschen = new JButton("Reset");
- Löschen.setBounds(520, 450, 200, 30);
- Löschen.addActionListener(actionListener);
- frame.add(Löschen);
- //Radirgummi
- radirgummi = new JButton("Radirgummi");
- radirgummi.setBounds(520, 530, 200, 30);
- radirgummi.addActionListener(actionListener);
- frame.add(radirgummi);
- //Größe einstellbar
- Big = new JSlider(JSlider.HORIZONTAL,1, 10, 4);
- frame.add(Big);
- Big.setMajorTickSpacing(9);
- Big.setMinorTickSpacing(1);
- Big.setPaintTicks(true);
- Big.setPaintLabels(true);
- Big.setForeground(new Color(0, 0, 0));
- Big.setBounds(520, 490, 200, 35);
- Big.addChangeListener(new ChangeListener() {
- @Override
- public void stateChanged(ChangeEvent e) {
- int r = Big.getValue();
- drawArea.radius = r;
- }
- });
- // create draw area
- drawArea = new DrawArea();
- drawArea.radius = 4;
- // add to content pane
- content.add(drawArea);
- //Setze Frame größe
- frame.setSize(740, 600);
- //Setze frame nicht größenverziebar
- frame.setResizable(false);
- // can close frame
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- // show the swing paint result
- frame.setVisible(true);
- // Now you can try our Swing Paint !!! Enjoy <img draggable="false" class="emoji" alt="😀" src="https://s.w.org/images/core/emoji/2.3/svg/1f600.svg">
- }
- private void addLog(JFrame controls) {
- Font font = new Font("Calibri", Font.BOLD, 20);
- log = new JTextArea();
- log.setEditable(false);
- log.setFont(font);
- log.setForeground(new Color(0, 0, 0));
- String Text="Rateversuche:\n";
- log.setText(Text);
- anzeige = new JScrollPane(log);
- anzeige.setBounds(520, 0, 200, 400);
- controls.add(anzeige);
- }
- public static void addToLog(String text){
- log.setText(log.getText()+text+"\n");
- }
- public static void rollenswaper(){
- frame.dispose();
- frame=null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement