NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package wisielec;
import java.awt.GridLayout;

public class Main extends JFrame {

private static final long serialVersionUID = -8440513601002601723L;

JFrame ramka;
JLabel l, l2, l3, l4, liczbaPunktowLabel;
JPasswordField passField;
JTextField textField2;
GridLayout gridLayout;
JButton button, button2;
JLabel costam, costam1, costam2;

String haslo;
String wynik; // _ _ _

int liczbaBledow;
int liczbaPunktow;

public Main() {

liczbaPunktow = 0;
haslo = "";
//ustawienia okna
ramka = new JFrame();
// Po zamknięciu okna, aplikacja ma zakończyc działanie
ramka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Ustalamy rozmiar okna
ramka.setSize(600, 240);
//wartosc NULL ustawia okno na środku ekranu
ramka.setLocationRelativeTo(null);
//nazwa okna
ramka.setTitle("GRA W SZUBIENICĘ- WERSJA TEKSTOWA");

//formatowanie labelów

costam = new JLabel("");
costam1 = new JLabel("SZUBIENICA");
costam1.setFont(new Font("Tahoma", Font.PLAIN, 20));
costam2 = new JLabel("");
l = new JLabel("hasło"); //napis hasło
l.setFont(new Font("Tahoma", Font.PLAIN, 13));
l2 = new JLabel("wpisz znak");
l2.setFont(new Font("Tahoma", Font.PLAIN, 13));
l3 = new JLabel("wynik");
l3.setFont(new Font("Tahoma", Font.PLAIN, 13));
l4 = new JLabel("liczba bledow");
l4.setFont(new Font("Tahoma", Font.PLAIN, 13));
liczbaPunktowLabel = new JLabel("liczba punktow: 0");
liczbaPunktowLabel.setFont(new Font("Tahoma", Font.PLAIN, 13));
passField = new JPasswordField(); //label hasła
textField2 = new JTextField(); //label 'wpisywania znaku'

// FlowLayout flowLayout = new FlowLayout();
gridLayout = new GridLayout(4, 3, 15, 10); //rozmieszczenie labelów w oknie

//formatowanie labelów
button = new JButton("Zacznij grę"); //przycisk 'zatwierdź'
button.setBackground(new Color(0, 255, 127));
button.setFont(new Font("Tahoma", Font.PLAIN, 13));
button2 = new JButton("Typuj znak"); //przycisk 'typuj znak'
button2.setBackground(new Color(255, 0, 0));
button2.setFont(new Font("Tahoma", Font.PLAIN, 13));

ramka.getContentPane().setLayout(gridLayout);

//dodawanie labelów do okna
ramka.getContentPane().add(costam);
ramka.getContentPane().add(costam1);
ramka.getContentPane().add(costam2);
ramka.getContentPane().add(l);
ramka.getContentPane().add(passField);
ramka.getContentPane().add(button);
ramka.getContentPane().add(l2);
ramka.getContentPane().add(textField2);
ramka.getContentPane().add(button2);
ramka.getContentPane().add(l3);
ramka.getContentPane().add(l4);
ramka.getContentPane().add(liczbaPunktowLabel);

// akcja do przycisku ropocznij
ActionListener al = new ActionListener() {

// @Override
public void actionPerformed(ActionEvent arg0) {
l4.setText("");
liczbaBledow = 0;
// pobranie hasla z text field
char[] c;
c = passField.getPassword();
haslo = ZamienNaString(c);

// uzpelnienie wyniku znakami _ _ _ _ _ _ zależnoc od długosci
// gasla
wynik = "";
for (int i = 0; i < haslo.length(); i++) {
wynik += "_ ";
}
// ustawiwnie wyniku do label
l3.setText(wynik);
}

};

// akcja do przycisku typuj
ActionListener al2 = new ActionListener() {

// @Override
public void actionPerformed(ActionEvent arg0) {
// pobranie zgadywanej literki z tekst field
String s = "";
s = textField2.getText().toString();

// sprawdzenie czy liera wystepuje w hasle
String strPom = "";
boolean czyWystepuje = false;
for (int i = 0; i < haslo.length(); i++) {

char cc = haslo.charAt(i);
if (s.equals(String.valueOf(haslo.charAt(i)))) {
// wstaw s zamiast "_ "
strPom += s;
strPom += " ";
czyWystepuje = true;
} else {
// przepisz
strPom += wynik.charAt(2 * i);
strPom += wynik.charAt(2 * i + 1);

}
}
// liczbaBledow += czyWystepuje ? 0:1;
if (!czyWystepuje) {
liczbaBledow++;
}
System.out.println(liczbaBledow);
wynik = strPom;
l3.setText(wynik);

// sprawdzenie czy liczba bledow przekracza dopuszczalna
if (liczbaBledow == 6) {
l4.setText("Koniec gry. Przegrałes. nLiczba błędów wyniosla "
+ liczbaBledow);

}

// pobierz tekst z ss= l3 (wynik)
// porownaj teskt z haslem
// for

// if ss.equals(haslo) dodaj punkt
}

};

button.addActionListener(al);
button2.addActionListener(al2);

// _ _ a _ _ a

ramka.setVisible(true);
}

protected String ZamienNaString(char[] c) {
String temp = "";
for (int i = 0; i < c.length; i++) {
temp += c[i];
}
return temp;
}

public static void main(String args[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Main();
}
});

}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.