- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有几个问题,请原谅我的英语!问题:
程序应该创建一个 JuliaSet。没有导入的类 Controller :
public class JuliaController extends WindowAdapter implements ActionListener {
private JuliaView view;
private JuliaModel model;
private String linkBuffer;
public JuliaController(){
model = new JuliaModel();
System.out.println("true!");
view = new JuliaView("JuliaMenge");
view.makeView();
}
@Override
public void actionPerformed(ActionEvent arg0) {
String action = arg0.getActionCommand();
if(action.equals(view.ACTION_CLEAR))
{
//Clear Graphics
view.setBtClear();
}
if(action.equals(view.ACTION_COMPLEX))
{
String input = view.getComplex();
view.setTfComplex(); //Zurücksetzen des Felds!
model.juliaBerechnung(input);
view.getBtPaint(); //Setzt den Button auf anklickbar
//Paint Button anklickbar machen
}
if(action.equals(view.ACTION_ENDE))
{
view.release();
System.exit(0);
}
if(action.equals(view.ACTION_LINK))
{
String inLink = view.getTfLink();
view.setTfLink();
try {
model.juliaBerechnung(dataInList(inLink));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
view.getBtPaint();
}
if(action.equals(view.ACTION_PAINT))
{
//Erzeuge Graphics!
view.getBtPaint(); //Button nicht mehr anklickbarkeit
}
}
public String dataInList(String link)throws IOException
{
String temp="";
BufferedReader inBuffer = null;
try {
inBuffer = new BufferedReader(new FileReader(new File(link)));
while((temp=inBuffer.readLine())!=null)
{
//System.out.println("Buffer : "+temp);
linkBuffer += temp;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int dateiLength = linkBuffer.length();
inBuffer.close();
char c;
int index=0;
for(int i = index;index<dateiLength;index++){
c = linkBuffer.charAt(index);
if((c=='+')||(c=='-'))break;
}
temp = "";
for(int i=index;i<index+8;i++)
{
temp+=linkBuffer.charAt(i);
}
return temp; //Keine Anhang in der Datei
}
public void release() {
// TODO Auto-generated method stub
model = null;
view = null;
}
public void windowClosing( WindowEvent we)
{
view.release();
}
}
查看:
public class JuliaView extends JFrame implements Observer{
//:::: ACTIONS
public final String ACTION_ENDE = "Ende";
public final String ACTION_PAINT = "Paint";
public final String ACTION_COMPLEX = "+a.x+b.x";
public final String ACTION_LINK = "Link";
public final String ACTION_CLEAR = "Clear";
//:::: Components
private JButton btEnde;
private JButton btPaint;
private JButton btClear;
public JuliaPanel drawArea; //Bereich für Paint
//private JButton btAutoPaint;
private JTextField tfComplex;
private JTextField tfLink;
//:::: Observer
private JuliaModel model;
private JuliaController controller;
private JuliaBild map;
public JuliaView(String titel){
super(titel);
this.model = model;
//this.map = model.getMap(); //??????//Iterationsarray einbinden
//this.model.addObserver(this);
//controller = makeController();
initForm();
//makeView();
}
void makeView() {
resetView();
// Fenster
addWindowListener( controller);
pack();
setVisible( true);
}
/*private JuliaController makeController() { ?????????????????
return new JuliaController();
}*/
/**
* Anordnen der Komponenten im GridBag
*/
private void initForm(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new GridBagLayout());
this.setBounds(200, 200, 800, 600);
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(15,15,15,15);
//this.add(btAutoPaint,c);
// TextField für Kompleze Zahl
tfComplex = new JTextField(ACTION_COMPLEX,8);
tfComplex.addActionListener(controller);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 2;
this.getContentPane().add(tfComplex,c);
// Link
tfLink = new JTextField(ACTION_LINK);
tfLink.addActionListener(controller);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 2;
this.getContentPane().add(tfLink,c);
// Paint Button
btPaint = new JButton(ACTION_PAINT);
btPaint.setEnabled(false);
btPaint.addActionListener(controller);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 2;
c.ipady = 40;
this.getContentPane().add(btPaint,c);
//CLS Button
btClear = new JButton(ACTION_CLEAR);
btClear.addActionListener(controller);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 4;
c.gridwidth = 2;
this.getContentPane().add(btClear,c);
//Exit Button
btEnde = new JButton(ACTION_ENDE);
btEnde.addActionListener(controller);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1;
c.gridy = 5;
c.gridwidth = 1;
this.getContentPane().add(btEnde,c);
//draw area
drawArea = new JuliaPanel(); //Place for the JuliaSet
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 2;
c.gridy = 0;
c.gridwidth = 6;
this.getContentPane().add(drawArea,c);
setVisible( true);
pack();
}
public void resetView(){
this.tfComplex.setText("+a.x+b.x");
this.tfLink.setText("c:/...");
//drawArea.paint(g);
}
@Override
public void update(Observable m, Object o) {
// TODO Auto-generated method stub
if(model == m) setBtPaint(); //???
}
public void setBtPaint()
{
btPaint.setText(ACTION_PAINT);
btPaint.requestFocus();
btPaint.setEnabled(true);
drawArea.setKoordinaten(map);
//Zeichnen
//drawArea.repaint();
drawArea.print(getGraphics());
//drawArea.paint(getGraphics());
}
public void getBtPaint()
{
btPaint.setText(ACTION_PAINT);
drawArea.createImage();
btPaint.requestFocus();
btPaint.setEnabled(false); //anklickbarkeit
}
public void setBtClear()
{
btClear.setText(ACTION_CLEAR);
resetView();
drawArea.clearImage();
btClear.requestFocus();
}
public void setTfComplex()
{
tfComplex.setText(ACTION_COMPLEX);
tfComplex.setCaretPosition(tfComplex.getText().length());
tfComplex.requestFocus();
}
public void setTfLink()
{
tfLink.setText(ACTION_LINK);
tfLink.setCaretPosition(tfLink.getText().length());
tfLink.requestFocus();
}
public void getBtEnde()
{
btEnde.setText(ACTION_ENDE);
btEnde.requestFocus();
}
public String getComplex()
{
String temp = "";
temp = tfComplex.getText();
return temp;
}
public String getTfLink()
{
String temp = tfLink.getText();
return temp;
}
public void release(){
dispose();
// Controller
controller.release();
controller = null;
// Model
model.deleteObserver( this);
model = null;
}
}型号:
public class JuliaModel extends Observable{
//private Complex startWert;
private Complex konst;
private String pfad;
private JuliaBild map;
public JuliaModel()
{
//startWert = new Complex(re, im);
konst = new Complex(1.0,1.0);
pfad = "";
makeBild();
}
private void makeBild()
{
map = new JuliaBild(600,600);
System.out.println("bild true");
}
public JuliaModel(double reK, double imK)
{
map = new JuliaBild(600,600);
//startWert = new Complex(re, im);
konst = new Complex(reK,imK);
pfad = "";
}
private int grundAlgoIt(double x,double y)
{
Complex temp = new Complex(x,y);
double xTemp=0;
for(int n=0;n<256;n++)
{
if(temp.abs()<4){return n;}
xTemp = Math.pow(temp.getRe(), 2)-Math.pow(temp.getIm(), 2) + konst.getRe();
temp.setIm((2*temp.getIm()*temp.getRe())+konst.getIm());//y=
temp.setRe(xTemp);
}
return 0;
}
void juliaBerechnung(String input)
{
double xmin = -2.0;//fx
double ymin = -2.0;//fy
double width = 4.0;//fw //Weg im Koordinatensystem
double height = 4.0;//fh
double schrittWeite = 4.0/600;
stringToKonst(input);
//Complex temp = new Complex(xmin-schrittWeite,1);
double xTemp,yTemp;
xTemp = xmin-schrittWeite;
//durch die Pixel gehen
for(int j=0;j<600;j++)
{
xTemp = xTemp+schrittWeite;
yTemp = ymin;
for(int i=0;i<600;i++)
{
yTemp = yTemp + schrittWeite;
map.setBild(j,i,grundAlgoIt(xTemp,yTemp));
}
}
}
private void stringToKonst(String in)
{
char cBuffer;
String sBuffer="";
double im = 0;
double re = 0;
for(int a=0;a<=4;a+=4)
for(int i=0;i<4;i++)
{
cBuffer = in.charAt(i+a);
sBuffer+=cBuffer;
if(a==0&&i==4)
{
re = Double.parseDouble(sBuffer);
}
if(a==4&&i==4)
{
im = Double.parseDouble(sBuffer);
}
}
konst.setNumber(re, im);
}
public JuliaBild getMap()
{
return map;
}}
感谢您的帮助!
最佳答案
My actionPerformed in my controller dont react
这是因为您从未使用任何能够生成 ActionEvent
的内容来注册 Controller
and I dont know how to use the update(model,object) method in the View.
当模型的状态发生更改时,将代表您的模型调用 update
方法。您应该根据模型的新状态更新 View 。
如果您的模型支持多个属性,则 PropertyChangeListener
可能更适合。如果模型具有不同的状态,您可能最好定义自己的监听器,该监听器定义模型可能触发的状态。
但是,同样,它永远不会被调用,因为您永远不会向其中添加 Observer
The next problem is my GridBag. It looks chaotic although the code is orientated on the oracle example.
是的,这就是适合您的 GridBagLayout
No the Last one. in the view line 41 i get a NPE as a result of a class initialised in the Model. dont no why. I allready testes if the Class is constructed and yes it is
哪一个是第 41 行?堆栈跟踪是什么样的?
首先定义 View 和 Controller 之间的契约。定义 Controller 可以在 View 上执行的操作以及 View 愿意接受的事件监听器。
通常,我避免将监听器直接附加到 Controller 中的 View 控件,而是定义 View 可以生成的事件,这样,您可以解耦两者之间的契约,并允许 View 和 Controller 的不同实现一起工作.
例如,如果您有一个按钮,该按钮假定表示用户已读取以处理输入,那么您可以定义一个 View 支持的监听器之一中的 userAcceptedInput
事件。这样,另一个实现可以使用一些其他机制来触发事件,而 Controller 不关心。
有关该主题的更多讨论请查看:
关于java - mvc 和 GridBagLayout 中的 ActionPerformed 和 update(Model,Object),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31281196/
我遵循了一本名为“Sitepoint Full Stack Javascript with MEAN”的书中的教程,我刚刚完成了第 6 章,应该已经创建了一个带有“数据库”的“服务器”。数据库只不过是
在 Jquery 中,我创建两个数组,一个嵌入另一个数组,就像这样...... arrayOne = [{name:'a',value:1}, {name:'b',value:2}] var arra
这个问题在这里已经有了答案: What is the explanation for these bizarre JavaScript behaviours mentioned in the 'Wa
我被放在别人的代码上,有一个类用作其他组件的基础。当我尝试 ng serve --aot(或 build --prod)时,我得到以下信息。 @Component({ ...,
我正在测试一些代码,并使用数据创建了一个 json 文件。 问题是我在警报中收到“[object Object],[object Object]”。没有数据。 我做错了什么? 这是代码:
我想打印 [object Object],[object Object] 以明智地 "[[{ 'x': '1', 'y': '0' }, { 'x': '2', 'y': '1' }]]"; 在 ja
我有一个功能 View ,我正在尝试以特殊格式的方式输出。但我无法让列表功能正常工作。 我得到的唯一返回是[object Object][object Object] [object Object]
在使用优秀的 Sim.js 和 Three.js 库处理 WebGL 项目时,我偶然发现了下一个问题: 一路走来,它使用了 THREE.Ray 的下一个构造函数: var ray = new THRE
我正在使用 Material UI 进行多重选择。这是我的代码。 {listStates.map(col => (
我的代码使用ajax: $("#keyword").keyup(function() { var keyword = $("#keyword").val(); if (keyword.
我遇到了下一个错误,无法理解如何解决它。 Can't resolve all parameters for AuthenticationService: ([object Object], ?, [o
我正在尝试创建一个显示动态复选框的表单,至少应选中其中一个才能继续。我还需要获取一组选中的复选框。 这是组件的代码: import { Component, OnInit } from '@angul
我正在开发 NodeJs 应用程序,它是博客应用程序。我使用了快速验证器,我尝试在 UI 端使用快速闪存消息将帖子保存在数据库中之前使用闪存消息验证数据,我成功地将数据保存在数据库中,但在提交表单后消
我知道有些人问了同样的问题并得到了解答。我已经查看了所有这些,但仍然无法解决我的问题。我有一个 jquery snipet,它将值发送到处理程序,处理程序处理来自 JS 的值并将数据作为 JSON 数
我继承了一个非常草率的项目,我的任务是解释为什么它不好。我注意到他们在整个代码中都进行了这样的比较 (IQueryable).FirstOrDefault(x => x.Facility == fac
我只是在删除数组中的对象时偶然发现了这一点。 代码如下: friends = []; friends.push( { a: 'Nexus', b: 'Muffi
这两个代码片段有什么区别: object = nil; [object release] 对比 [object release]; object = nil; 哪个是最佳实践? 最佳答案 object
我应该为其他人将从中继承的第一个父对象传递哪个参数,哪个参数更有效 Object.create(Object.prototype) Object.create(Object) Object.creat
我在不同的对象上安排不同的选择器 [self performSelector:@selector(doSmth) withObject:objectA afterDelay:1]; [self per
NSLog(@"%p", &object); 和 NSLog(@"%p", object); 有什么区别? 两者似乎都打印出一个内存地址,但我不确定哪个是对象的实际内存地址。 最佳答案 这就是我喜欢的
我是一名优秀的程序员,十分优秀!