Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Spiel;
- import java.awt.BasicStroke;
- 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.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JSlider;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- public class MyPanelRater extends JPanel {
- public Main m;
- public Connection con;
- public MyPanelRater() {
- this.show();
- }
- public GetRandomWord randomword;
- private static DrawAreaRater drawArea;
- private Color oldColor = Color.BLACK;
- private JButton send;
- private JTextArea log;
- private JScrollPane anzeige;
- private JTextField eingabe;
- private static String word;
- public static JFrame frame;
- public void show() {
- // create main frame
- frame = new JFrame("Raten");
- Container content = frame.getContentPane();
- //Set buttons Action listener
- ActionListener actionListener = new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == send) {
- addToLog(eingabe.getText().replaceAll(" ", "_"));
- con.serversendMessage("ratewort "+eingabe.getText().replaceAll(" ", "_"));
- if(eingabe.getText().equalsIgnoreCase(word)){
- JOptionPane.showMessageDialog(frame, "Das Wort war richtig!");
- rollenswaper();
- con.serversendMessage("rollenswaper");
- String random = randomword.getRandomWord();
- JOptionPane.showMessageDialog(frame, "Bitte male "+random);
- con.serversendMessage("start rate "+random);
- }
- }
- }
- };
- //
- JPanel controls = new JPanel();
- addLog(frame);
- //Rate feld
- eingabe = new JTextField();
- frame.add(eingabe);
- eingabe.setText("Das wort hier Raten");
- eingabe.setBounds(520, 410, 200, 30);
- //send Button
- send = new JButton("send");
- send.setBounds(520, 450, 200, 30);
- send.addActionListener(actionListener);
- frame.add(send);
- // create draw area
- drawArea = new DrawAreaRater();
- 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="Rateverlauf:\n";
- log.setText(Text);
- anzeige = new JScrollPane(log);
- anzeige.setBounds(520, 0, 200, 400);
- controls.add(anzeige);
- }
- public void setword(String word){
- this.word = word;
- }
- public static void drawLine(int radius, int oldX, int oldY, int currentX, int currentY,int r ,int g, int b){
- drawArea.drawLine(radius, oldX, oldY, currentX, currentY, r, g, b);
- }
- public static void clear(){
- drawArea.clear();
- }
- private void addToLog(String text){
- log.setText(log.getText()+text+"\n");
- }
- public static void rollenswaper(){
- frame.dispose();
- MyPanel MyP = new MyPanel();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement