我正在练习MVC风格的编程.我在一个文件中有一个Mastermind游戏,工作正常(可能除了"Check"按钮在开始时不可见).
http://paste.pocoo.org/show/226726/
但是当我把它重写为模型,视图,控制器文件时 - 当我点击空Pin(应该更新,并重新绘制新颜色)时 - 注意到了.谁能在这里看到任何问题?我尝试在不同的地方放置repaint(),但它根本不起作用:/
主要:
public class Main {
public static void main(String[] args){
Model model = new Model();
View view = new View("Mastermind", 400, 590, model);
Controller controller = new Controller(model, view);
view.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
型号:
import java.util.Random;
public class Model{
static final int
LINE = 5,
SCORE = 10, OPTIONS = 20;
Pin pins[][] = new Pin[21][LINE];
int combination[] = new int[LINE];
int curPin = 0;
int turn = 1;
Random generator = new Random(); …Run Code Online (Sandbox Code Playgroud) 我正在使用构建HTML编辑器JEditorPane,但是我遇到了一些与Foreground Actions不一致的性能问题.我的编辑器的简化版本有三个动作:将字体颜色更改为红色或蓝色,或更改字体大小.现在使用以下testFile.html文件:
<html>
<head><title>Title</title></head>
<body link="#0000FF" bgcolor="white">
<font size="4" face="arial" color="black">Some test text</font>
<font size="3" face="arial" color="black">Some new test text </font>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
有时我可以在编辑器中突出显示一些文本,然后按红色或蓝色按钮,它可以正常工作,即它会改变颜色.在其他场合(即如果我关闭我的JVM并再次启动它)颜色将不会改变直到我StyledEditorKit.FontSizeAction在相同的文本上应用.
我是如何应用的ForegroundActions?或者这可能是一些Java bug?
代码如下:
public class EditorTest extends JFrame{
private JEditorPane editorPane;
public EditorTest()
{
editorPane = new JEditorPane();
editorPane.setContentType("text/HTML");
getContentPane().add(editorPane, BorderLayout.CENTER);
editorPane.setEditorKit(new HTMLEditorKit());
Action a = new StyledEditorKit.ForegroundAction("RedColor", Color.RED);
editorPane.getActionMap().put("RedColor", a);
JToolBar bar = new JToolBar();
JButton button = new JButton("blue");
button.addActionListener(new StyledEditorKit.ForegroundAction (
"set-foreground-red", Color.blue));
bar.add(editorPane.getActionMap().get("font-size-12")).setText("12");
bar.add(button);
bar.add(editorPane.getActionMap().get("RedColor")).setText("Red");
getContentPane().add(bar, …Run Code Online (Sandbox Code Playgroud)