UITextField, изменяющий размер шрифта через Интерфейсного Разработчика

В субботу я уже слишком поздно занимаюсь алгеброй, поэтому я буду придерживаться предложения об изменении структуры вашей программы. Во-первых, вы можете выполнить все с помощью одного класса, содержащего вопросы и оценки для пользователя. Методы в этом классе могут быть выбраны через главное меню. Я написал пример того, как я буду структурировать это на основе стандартной методологии ООП Java. В моей программе основному классу не нужен статический класс, он зацикливает меню, и там делается выбор вопроса. Мои методы имеют один вопрос, вы можете добавить столько, сколько захотите, в меню, важна структура.

 import java.util.Scanner;

//This class contains the two methods and over-all score
class Material {
private int score;
//The user chooses this or the earth method
public void sky() {

    String answer = "null"; 
    int count = 0;
    Scanner input = new Scanner(System.in);
   //within the method, is this while loop which gives a hint after 3 attempts.
    while (!answer.equals("blue") && (!answer.equals("exit"))) {
        System.out.println("What color is the sky? 'exit' to exit");
        answer = input.nextLine();
        count++;
        if (count == 3)
            System.out.println("Hint: It starts with a 'b'");
    }

    if (answer.equals("blue"))
        score += 1;//The score will increment if the choice is correct,
    else//or else leave with nothing...
        return;
}

    //This method is the same as the sky() method, just different question and answer.
public void earth() {

    String answer = "null";
    int count = 0;
    Scanner input = new Scanner(System.in);

    while (!answer.equals("iron") && (!answer.equals("exit"))) {
        System.out.println("What is the core made of? 'exit' to exit");
        answer = input.nextLine();
        count++;
        if (count == 3)
            System.out.println("Hint: It starts with a 'i'");
    }

    if (answer.equals("iron"))
        score += 1;
    else
        return;

}

public int getScore() {
    return score;
}

}

public class Questions {

public static void main(String[] args) {
    //No static methods needed, here is an instance of our test materia class.
    Material material = new Material();

    //The choice and scanner are instantiated here.
    int choice = 0;
    Scanner input = new Scanner(System.in);

    //This while loop uses a switch statement to choose the methods for the questions
    while (choice != 3) {

        if (material.getScore() == 3) {
            System.out.println("Good job, you scored three right.");
            return;
        }

        System.out.println("SCORE: " + material.getScore());
        System.out.println("Anwer questions about the sky: 1");
        System.out.println("Answer quetions about the earth: 2");
        System.out.println("Exit: 3");
        choice = input.nextInt();
       //choices are 1 , 2 for questions, and 3 to leave.
        switch (choice) {
        case 1:
            material.sky();
            break;
        case 2:
            material.earth();
            break;
        case 3:
            System.out.println("Exiting...");
            break;
        default:
            System.out.println("not a valid number choice...");

        }
    }

}// main
}// class
6
задан Coocoo4Cocoa 19 February 2009 в 16:13
поделиться

1 ответ

Удостоверьтесь, что Вы сняли флажок с опцией "Adjust to fit" на UITextField. Иначе, если Ваш текст будет длиннее, чем поле, то платформа автоматически уменьшит текст, чтобы заставить его соответствовать.

7
ответ дан 17 December 2019 в 00:15
поделиться
Другие вопросы по тегам:

Похожие вопросы: