我正在设计一个与 DFA 相关的程序..所以我想把 Q0 或 Q1 之类的东西放在圈子里,但我不知道怎么做..有人可以看看我的代码并告诉我怎么做吗?如果可以直接放置一个将出现在圆圈内的名称,那就太好了,因为我认为很难为 JLabel 设置位置。这是我的代码:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class midterm extends JFrame
{
JPanel mainpanel;
JPanel gamepanel;
JPanel controls;
ExitButtonListener end=new ExitButtonListener();
public midterm()
{
super("My DFA Design");
setSize(700,700);
setLocation(400,100);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
panel();
this.getContentPane().add(mainpanel);
this.pack();
setVisible(true);
setSize(400,400);
}
public static void main(String[] args)
{
midterm frame=new midterm();
}
void panel()
{
mainpanel=new JPanel();
mainpanel.setLayout(new BorderLayout());
gamepanel=new JPanel();
gamepanel.setBorder(BorderFactory.createTitledBorder("Deterministic Finite Automata"));
gamepanel.setLayout(new GridLayout(2,3));
controls = new JPanel();
controls.setLayout(new BorderLayout());
controls.setBorder(BorderFactory.createTitledBorder("Control"));
JButton newGame = new JButton("Reset");
newGame.addActionListener(new NewButtonListener());
controls.add(newGame, BorderLayout.NORTH);
JButton exitGame = new JButton("Exit");
exitGame.addActionListener(end);
controls.add(exitGame, BorderLayout.SOUTH);
mainpanel.add(gamepanel, BorderLayout.CENTER);
mainpanel.add(controls, BorderLayout.EAST);
mainpanel.setVisible(true);
q1 c1=new q1();
q2 c2=new q2();
q3 c3=new q3();
gamepanel.add(c1);
gamepanel.add(c2);
gamepanel.add(c3);
}
class ExitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
}
class NewButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
}
}
class q1 extends JPanel
{
final int radius=25;
public void paint(Graphics gr)
{
setBackground(Color.black);
gr.drawOval((100/2-radius),(100/2-radius), radius*2, radius*2);
}
}
class q2 extends JPanel
{
final int radius=25;
public void paint(Graphics gr)
{
setBackground(Color.black);
gr.drawOval((95/2-radius),(100/2-radius), radius*2, radius*2);
}
}
class q3 extends JPanel
{
final int radius=25;
public void paint(Graphics gr)
{
setBackground(Color.black);
gr.drawOval((250/2-radius),(50/2-radius), radius*2, radius*2);
}
}
}