טקסט בעברית JAVA

ehudl1

New member
טקסט בעברית JAVA

שלום,
אני יודע שאפשר לכתוב את הטקסט בעברית ב- JAVA אבל הכל מיושר תמיד לצד שמאל.
רציתי לדעת אם יש אפשרות שזה יסתדר/ לסדר בצורה כלשהי מימין לשמאל?

תודה.
 

BravoMan

Active member
מה הכוונה "לתכוב טקסט ב-Java"?

האם אתה בונה ממשק עם SWING או ספרייה אחרת?
או שאתה מדפיס טקסט בקונסול (שורת פקודה)?
 

ehudl1

New member
הסבר

נגיד יש לי שדות כאלה:
first name
last name
....
במקום לרשום yossi אני רוצה לרשום יוסי.
 

ehudl1

New member
ואני רוצה להציג את זה בחלון כלשהו

בגלל זה אני מדבר על יישור מימין לשמאל.
 

ehudl1

New member
שום דבר לא מונע ממני זה פשוט בצד שמאל

נגיד נפתח לי חלון כזה:

יוסי
0
0
0
0

אני רוצה שזה יהיה בצד ימין (0 זה נגיד חלון שאני צריך לבחור מתוך 4 אופציות)
ככה:
יוסי
0
0
0
0
 

BravoMan

Active member
שמע, אי אפשר לעזור לך כל עוד אתה כותב

"חלון כזה".

אתה משתמש ב-System.out.println כדי להציג את הנתונים?
או שאתה משתמש בספריית GUI כלשהי?

אם תבהיר מה זה בדיוק "החלון הזה" נוכל להסביר לך איך לגרום לו להתנהג כפי שאתה רוצה.

אולי פשוט תצרף את הקוד שאחראי על יצירת החלון?
 

ehudl1

New member
הנה משהו

import java.awt.*;
import java.awt.event.*;
import java.io.*;

import javax.swing.*;

import java.util.EventListener;
import java.util.Random;

public class Trivia extends JFrame implements ActionListener
{
private int i=0, grade=0;
private String str;
private int delay=10000;
private Timer timer= new Timer (delay, this);
private Questions q= new Questions();

private Container c = getContentPane();
private JTextField t_question;
private JTextField t_timer;
private ButtonGroup group= new ButtonGroup();
private JRadioButton choise1, choise2, choise3, choise4;
private JButton cButt= new JButton ("Play a new Game");

private int x_op1, x_op2, x_op3, x_op4;
private Random rand_op1= new Random();
private Random rand_op2= new Random();
private Random rand_op3= new Random();
private Random rand_op4= new Random();

public Trivia() throws FileNotFoundException
{
super("Trivia");

super.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
if (i<18)
{
if (grade>100)
{
grade=100;
JOptionPane.showMessageDialog(null,"You stoped the game, your grade is: "+grade);
}
else JOptionPane.showMessageDialog(null,"You stoped the game, your grade is: "+grade);
}
}
}
);

c.setLayout( new GridLayout(7,1));
t_question = new JTextField("Trivia Game");
c.add( t_question );

choise1=new JRadioButton("");
choise1.addActionListener(this);
c.add(choise1);
group.add(choise1);
choise2=new JRadioButton("");
choise2.addActionListener(this);
c.add(choise2);
group.add(choise2);
choise3=new JRadioButton("");
choise3.addActionListener(this);
c.add(choise3);
group.add(choise3);
choise4=new JRadioButton("");
choise4.addActionListener(this);
c.add(choise4);
group.add(choise4);

t_timer = new JTextField(" You have "+delay/1000+" seconds to answer the question");
c.add( t_timer );

add(cButt);
cButt.addActionListener(this);

ShowQuestions();
setSize(550,300);
setVisible(true);
}

public void ShowQuestions() throws FileNotFoundException
{
str=q.q.getQ();
t_question.setText(str);

x_op1=rand_op1.nextInt(4);
x_op2=rand_op2.nextInt(4);
x_op3=rand_op3.nextInt(4);
x_op4=rand_op4.nextInt(4);

str=q.q.getOp(x_op1);
choise1.setText(str);

while (x_op2==x_op1)
{
x_op2=rand_op2.nextInt(4);
}
str=q.q.getOp(x_op2);
choise2.setText(str);

while (x_op3==x_op1 || x_op3==x_op2)
{
x_op3=rand_op3.nextInt(4);
}
str=q.q.getOp(x_op3);
choise3.setText(str);


while (x_op4==x_op1 || x_op4==x_op2 || x_op4==x_op3)
{
x_op4=rand_op4.nextInt(4);
}
str=q.q.getOp(x_op4);
choise4.setText(str);

timer.start();

} // ShowQuestions



public void actionPerformed(ActionEvent e)
{
timer.stop();

if (e.getActionCommand()=="Play a new Game")
{
i=0;
try {
ShowQuestions();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
System.err.println("Error: " + e1);
}
}

if (e.getSource()==timer)
{
JOptionPane.showMessageDialog(null,"Time's up!");
if (grade>=5)
grade=grade-5;
else grade=0;
}
else
{
if (e.getActionCommand()==q.q.getOp(1))
grade=grade+10;

else if (grade>=5)
grade=grade-5;
else grade=0;
}

if (i<18 && e.getActionCommand()!="Play a new Game")
{
i++;
try
{
ShowQuestions();
} catch (FileNotFoundException e1)
{
// TODO Auto-generated catch block
System.err.println("Error: " + e1);
}
}
else
{
if (grade>100)
{
grade=100;
JOptionPane.showMessageDialog(null,"Your grade is: "+grade);
}
else JOptionPane.showMessageDialog(null,"Your grade is: "+grade);
}
} //actionPerformed


public static void main(String[] args) throws FileNotFoundException
{
Trivia T= new Trivia();
T.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}


כל מקום שיש JField לדוגמא אני רוצה שיהיה כתוב בעברית. אם זה נמשך מקובץ כמו במקרה הזה הוא "מיישר" לשמאל.
 

ehudl1

New member
אוקי, ולגבי השאר

הרי יש לי גם טסקט וגם אופציות בחירה.
 

ehudl1

New member
זה נותן שגיאת קומפילציה

Multiple markers at this line
- Syntax error on token ".", ... expected
- Syntax error on token "setHorizontalAlignment", Identifier expected after
this token
 
למעלה