我想我已经把自己写成了一个角落.我正在尝试使用java swing做这个效果.
单击下一步按钮,从文件中加载一个新行(通过行索引号),然后如果文件中的行的日期尚未到达,则使下一个按钮变灰.我的问题是,当我有以下代码时:
    Scanner input = new Scanner(System.in);
    System.out.println("Enter week number");
    int j = input.nextInt();
    String[] strArray = new String[4];        
    xmlLoader(j, strArray);
    JButton nextButton = new JButton("Next");
    nextButton.setBounds(750, 250, 80, 30);
    nextButton.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent ae){
           j++;
           doNext(j, nextButton);
       } 
    });
Run Code Online (Sandbox Code Playgroud)
我不能通过j,因为它不是最终的,如果它是最终的,我无法改变按钮上的任何东西,helpppp!
特定错误:从内部类中访问局部变量j; 需要宣布最终
我已经非常喜欢C++中的一些结构,我最近一直在将一些旧的学校项目移植到java,但是遇到了一些陷阱,这些问题都没有通过简单的谷歌搜索来解决......所以我想到了我在这里问:
在C++中我很喜欢的Stringstream,vector,list,和dequeue,但一直没能找到其中的任何适当的文件.当我尝试使用时Vector,netbeans告诉我它已被弃用,这是否意味着其他一些代码占据了它的位置?我应该使用其他容器吗?
谢谢!
在visual basic.net中,我一直在使用groupboxes和那种性质的东西,有没有办法将项目分组到一个盒子,比如按钮,并使用groupbox作为容器移动/保存所有内容而不是以任何方式可见?(也许没有装饰?)
我已经尝试使groupbox不可见,但这也使得groupbox中的所有项目都不可见.
所以最近我开始讨论如何解决问题,具体问题是:如何找到所有pallindromes在1到100万之间.我说,"使用atoi创建一个字符串,使用for循环来反转字符串,使用strcmp来比较有问题的字符串.
几分钟后,有人问"你为什么要在C++中使用C风格的解决方案." 我发现自己混淆了一种简单的,更"C++"的解决方法,直接易懂的代码.有人照顾我这个吗?
编辑:itoa not atoi
我昨晚写了一些java,我有两个看起来基本相似的构造函数,除了我的默认构造函数为我的对象提供了一些值,它是这样的:
testObject(){
     width=5;
     height=12;
     depth=7;
     //other stuff is the same as the next one
}
testObject(int x, int y, int z){
    width=x; 
    height = y;
    depth = z;
    //All the other stuff is the same as default
}
Run Code Online (Sandbox Code Playgroud)
所以在这种情况下,我能够转换代码来代替:
testObject(){
    this(5,12,7);
}
Run Code Online (Sandbox Code Playgroud)
这将默认构造函数中的值作为要构建的3-int构造函数发送回构造函数.有没有办法在C++中获得这种类型的功能?
我最近遇到了一个问题,我想不出一个好的解决方法.我正在使用案例结构来尝试将属性设置为将传递给对象构造函数的"字符".
例:
//note this is inside a function with a return type of int*
int selection;
cin >> selection;
int * iPtr;
switch(selection){
case 1:{
     int anArray[6] = {8,5,2,4,250,100} // str, dex, int, luck, hp, mp
     iPtr = anArray;
     return iPtr;
}
//more cases and such below
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,当我返回指针时,它似乎充满了大量的垃圾,而不是信息,而不是我期望它保留的信息.那是因为数组在范围的末尾被销毁了吗?如果是这样,我该怎么做才能使我的方法成为我希望它(获得一个指向我想要的值的指针).
谢谢!
我觉得我可能会在这里忽略一些非常简单的东西,但是我已经制作了一些代码来测试列表中的插入/拼接,并且我对我制作的代码产生了一个段错误.有人可以告诉我在哪里/为什么?
#include <iostream>    
#include <vector>
#include <list>
using namespace std;
int main(){
vector <int> iVec;
list <int> iList;
vector<int>::iterator vIt;
list <int>::iterator lIt;
for(int i = 0; i < 10; i++){
    iVec.push_back(i*10);
    iList.push_back(i*10);
}//0, 10, 20, 30....90
//0 <-- current pos of iterator lIt
lIt++;  
lIt++; 
//0, 10, 20
iList.insert(lIt, 3);
//Vector output loop
for(vIt = iVec.begin(); vIt!= iVec.end(); vIt++){
}
cout << endl << endl <<"List Contents: " <<endl << endl;
//List output loop
for(lIt = iList.begin(); lIt != …Run Code Online (Sandbox Code Playgroud)