小编riz*_*ize的帖子

使用Java Swing绘制多行

我正在学习使用Java Swing绘制线条以绘制迷宫.我可以在指定的位置绘制一条线,它显示得很好.但是当我想画多行时,只有最后一行显示.我的代码:

public class LabyrinthGUI extends JFrame {
...
Line line;
for (int i = 0; i < 10; i++) {
   line = new Line(i*25, 0, (i+1)*25, 50);
   this.getContentPane().add(line);
}
}

public class Line extends JPanel{
private int x1, y1, x2, y2;

public Line(int x1, int y1, int x2, int y2) {
    this.x1 = x1;
    this.y1 = y1;
    this.x2 = x2;
    this.y2 = y2;
}
public void paintComponent (Graphics g) {
    g.drawLine(x1, y1, x2, y2);

}
Run Code Online (Sandbox Code Playgroud)

我可能需要刷新一些东西,以显示用for-loop绘制的所有线条,但不知道是什么.

java swing

8
推荐指数
1
解决办法
2万
查看次数

Java将字符添加到字符串中

我在java程序中有两个字符串,我希望以某种方式混合以形成两个新字符串.要做到这一点,我必须从每个字符串中选取一些组成字符并添加它们以形成新字符串.我有这样的代码(this.eka和this.toka是原始字符串):

String muutettu1 = new String();
String muutettu2 = new String();
muutettu1 += this.toka.charAt(0) + this.toka.charAt(1) + this.eka.substring(2);
muutettu2 += this.eka.charAt(0) + this.eka.charAt(1) + this.toka.substring(2);
System.out.println(muutettu1 + " " + muutettu2);
Run Code Online (Sandbox Code Playgroud)

我正在为.charAt(x)部分获取数字,那么如何将字符转换为字符串?

java string char

5
推荐指数
3
解决办法
9万
查看次数

从Xcode链接到Boost

我想使用Boost-library编译Xcode(版本4.5.2.)项目.我已经在我的mac上成功安装了Boost,并收到以下消息:

The following directory should be added to compiler include paths:
XXX/boost_1_52_0
The following directory should be added to linker library paths:
XXX/boost_1_52_0/stage/lib
Run Code Online (Sandbox Code Playgroud)

如何在Xcode中添加编译器包含路径和链接器库路径?非常感谢.

c++ xcode linker boost

5
推荐指数
1
解决办法
6885
查看次数

Java将命令行参数传递给方法

我正在编写一个程序,它将两个单词作为命令行参数,对它们执行某些操作,并打印出结果.我正在编写一个类来处理这个问题,我的问题是:在类中的方法之间传递两个单词作为命令行参数的最佳方法是什么?为什么我不能在带有"args"的构造函数中使用通常的"this.variable ="?

java command-line arguments

3
推荐指数
1
解决办法
2万
查看次数

Java swing JLabel没有显示

在退出我的比赛时,我想展示一个"退出".exitscreen.gif在文件夹中,工作正常,但由于某种原因,只有空白框显示:

JPanel finishPanel = new JPanel();
JLabel finishLabel = new JLabel(new ImageIcon("welcomescreen.gif"));
finishPanel.add(finishLabel);
finishLabel.setSize(11 * 35, 11 * 35);
finishPanel.setPreferredSize(finishLabel.getSize());
this.frame.setVisible(false);
JFrame exitFrame = new JFrame("Thanks for playing");
exitFrame.getContentPane().add(finishPanel);
exitFrame.setLocationRelativeTo(null);
exitFrame.pack();
exitFrame.setVisible(true);
finishLabel.setVisible(true);
Run Code Online (Sandbox Code Playgroud)

this.frame只是我不再需要的另一个JFrame.

java swing jframe

3
推荐指数
1
解决办法
900
查看次数

Python:object作为另一个对象的参数

我有一个模块,包括Python中两个不同类的定义.如何使用一个类的对象作为另一个类的参数?比方说,我有Driver和Car的类定义,并且tuen想要一个Driver对象作为Car对象的参数.

python arguments class object

3
推荐指数
1
解决办法
2万
查看次数

在Matlab中实现对象容器的最佳方法

我正在使用面向对象的Matlab,但我想知道,列出同一类的所有实例的对象列表的最佳方法是什么?我希望能够在for循环中遍历列表,并为类的每个实例访问相同的函数。

oop matlab iterator list

3
推荐指数
1
解决办法
2239
查看次数

如何在C++中检查输出流是否是std :: cout?

我正在实现输出流运算符<< overload,我需要检查输出流参数os是std :: cout,如果没有,抛出std :: runtime_error - 我该如何检查它?

   friend std::ostream& operator<<(std::ostream& os, const Software &soft)
Run Code Online (Sandbox Code Playgroud)

c++ cout exception stream

2
推荐指数
1
解决办法
851
查看次数

Pandas从Python 3中的安全FTP服务器读取数据

我正在寻找一个简洁的解决方案,从Python 3中的安全FTP服务器读取数据(使用read_csv或read_sas)到Pandas Dataframe.我可以找到的所有示例都是许多行,有些是Python 2.不存在将您的用户名+密码插入Pandas read_csv-like方法以及ftp url和文件夹的简洁方法?

python csv ftp pandas

2
推荐指数
1
解决办法
2254
查看次数

通过将指针设置为NULL来初始化C中的堆栈

我正在尝试根据以下标头(stack.h)在C中实现堆栈:

#ifndef STACK_H
#define STACK_H

/* An element from which stack is consisting */
typedef struct stack_node_ss {
  struct stack_node_ss *next;    /* pointer to next element in stack */
  void *value;                  /* value of this element */
} stack_node_s;

/* typedef so that stack user doesn't have to worry about the actual type of
 * parameter stack when using this stack implementation.
 */
typedef stack_node_s* stack_s;

/* Initializes a stack pointed by parameter stack. User calls this after he
 * …
Run Code Online (Sandbox Code Playgroud)

c null initialization linked-list

1
推荐指数
1
解决办法
9464
查看次数

C++模板类copy-constructor和assignment-operator

我有一个模板类Triple的实现,它是一个容纳任意三种类型的容器.我的问题是,我的类将三个const引用作为参数值,并且值必须是私有的(定义),但是,我还必须实现copy-constructor和重载赋值运算符.

template <typename T1, typename T2, typename T3>
    class Triple
{
public:
    Triple()
    { }
    Triple(const T1 &a, const T2 &b, const T3 &c) : a(a), b(b), c(c)
    { }

    // copy constructor
    Triple(const Triple &triple) {
        a = triple.first();
        b = triple.second();
        c = triple.third();
    }

    // assignment operator
    Triple &operator=(const Triple& other) {
        //Check for self-assignment
        if (this == &other)
            return *this;

        a = other.first();
        b = other.second();
        c = other.third();

        return *this;
    }

  private:
    T1 const& a; …
Run Code Online (Sandbox Code Playgroud)

c++ templates class

1
推荐指数
1
解决办法
2551
查看次数

C++模板函数专业化

我必须为模板类实现非成员函数isHomogenous(Triple triple),定义为:

template <typename T1, typename T2, typename T3>
    class Triple
{
public:
    Triple()
    { }
    Triple(const T1 &a, const T2 &b, const T3 &c) : a(a), b(b), c(c)
    { }
...
Run Code Online (Sandbox Code Playgroud)

isHomogenous函数应返回一个bool值,指示参数triple中的所有三个值是否属于同一类型.我试过了:

template <typename T> bool isHomogenous(Triple<T, T, T> triple) {
    return true;
}

template <typename T1, typename T2, typename T3> bool isHomogenous(Triple<T1, T2, T3> triple) {
    return false;
}
Run Code Online (Sandbox Code Playgroud)

这不起作用,你可以提示我解决方案吗?

c++ templates specialization

1
推荐指数
1
解决办法
2548
查看次数

Java NullPointerException

我正在编写两个类来处理简单的拍卖.我有一个准备好工作的班级,处理单次拍卖的操作,现在我正在编写另一个类似拍卖行的班级,以跟踪所有可用的拍卖.在测试课程的以下部分时:

import java.util.ArrayList;

public class AuctionHouse {
    private ArrayList<DutchAuction> huutokaupat;

    public AuctionHouse() {
    }

    public void addAuction(DutchAuction newAuction) {
        huutokaupat.add(newAuction);
    }
}
Run Code Online (Sandbox Code Playgroud)

在一个带有以下代码的main方法中("kauppa"是一个经过测试和工作的对象变量):

AuctionHouse talo = new AuctionHouse();
talo.addAuction(kauppa);
Run Code Online (Sandbox Code Playgroud)

我明白了:

在ope.auction.dutch.DutchAuctionTest.main(DutchAuctionTest.java:54)的ope.auction.dutch.AuctionHouse.addAuction(AuctionHouse.java:13)中的线程"main"java.lang.NullPointerException中的异常

我该如何解决这个问题?

java algorithm runtime-error nullpointerexception

0
推荐指数
2
解决办法
573
查看次数