小编Vas*_* De的帖子

有效字符串的长度返回0

我有一个字符串

String A;
Run Code Online (Sandbox Code Playgroud)

和一些处理它的方法

public void setA(String A) throws AInvalidException{
    if(isAValid())
        this.A = A;
    throw new AInvalidException();
}

public boolean isAValid(){
    int aLength = getA().length();
    return b = (aLength==9) ? true: false;
}

public String getA(){
    return A;
}
Run Code Online (Sandbox Code Playgroud)

当我试图在主要部分看到我的弦长

AClass.setA("123456789");
Run Code Online (Sandbox Code Playgroud)

它说我的String无效,调试后我看到我的String长度为零.我可能做错了什么?

java string string-length

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

在CellRenderer中显示选定的行和列

我有一个JTable,每次我选择一个单元格,我想打印它的行和列索引.因此我使用getSelectedRow()getSelectedColumn()方法.运行以下代码:

TestTimeTable类

public class TestTimeTable extends JFrame{
    private final int rows = 10;
    private final int cols = 8;
    private final String daysOfTheWeek[] = {"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"};
    private final JPanel jTablePanel;
    private final JScrollPane scrollPane;
    private final JTable timeTable;
    private final Object[][] rowData;

    public TestTimeTable(){
        this.rowData = new Object[this.rows][this.cols];
        this.timeTable = new JTable(this.rowData,this.daysOfTheWeek){
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };

        this.timeTable.setRowHeight(200, 200);
        this.timeTable.setFillsViewportHeight(true);
        this.timeTable.setOpaque(true);
        this.timeTable.setColumnSelectionAllowed(true);
        this.timeTable.setRowSelectionAllowed(true);
        this.timeTable.setCellSelectionEnabled(true); …
Run Code Online (Sandbox Code Playgroud)

java swing jtable cells tablecellrenderer

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

如何将值更新为 Python 字典的值和键?

假设我们有这本字典:

thisdict =  {
"brand": ["Ford","Renault", "Nissan"],
"Ford": ["red", "blue", "green"]
}
Run Code Online (Sandbox Code Playgroud)

当我将“Ford”键值更改为“droF”时,我希望它也在品牌列表中更改,反之亦然,如下所示:

thisdict =  {
"brand": ["droF","Renault", "Nissan"],
"droF": ["red", "blue", "green"]
}
Run Code Online (Sandbox Code Playgroud)

有什么办法吗?

python dictionary python-3.x

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