- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 208 个按钮,我想使用数组为它们分配编号。这些按钮的顶部有不同的图像,当我输入相应的数字(代表屏幕上的按钮)时,我希望它们出现在屏幕上。二维数组可以忽略。我知道我必须删除这段代码并在这段代码的位置编写数组代码,但我不知道我必须做什么。
import java.awt.*;
import java.awt.event.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.lang.Object;
public class CBallMaze extends JFrame implements ActionListener
{
private JButton Jbuttonoption1;
private JButton Jbuttonoption2;
private JButton Jbuttonoption3;
private JButton Jbuttonblank1;
private JButton Jbuttonup;
private JButton Jbuttonblank2;
private JButton Jbuttonleft;
private JButton Jbuttonblank3;
private JButton Jbuttonright;
private JButton Jbuttonblank4;
private JButton Jbuttondown;
private JButton Jbuttonblank5;
private JButton Jbuttonexit;
private JButton Jbuttonact;
private Icon iconAct;
private JButton Jbuttonrun;
private Icon iconRun;
private JButton Jbuttonreset;
private Icon iconReset;
private Icon iconCompassnorth;
private Icon iconCompasseast;
private Icon iconCompasssouth;
private Icon iconCompasswest;
private JButton JButtoncompass;
private JPanel JPanelSouth;
private JPanel JPanelSouthButtons;
private JPanel JPanelSouthSlider;
private JPanel JPaneleast;
private JPanel JPaneleastoptionbutton;
private JPanel JPaneleastmiddle;
private JPanel JPaneleastcompass;
private JPanel JPaneleasttextfields;
private JTextField JTextField1;
private JLabel JLabelTextField1;
private JTextField JTextField2;
private JLabel JLabelTextField2;
private JTextField JTextField3;
private JLabel JLabelTextField3;
private JPanel JPanelnorth;
private JButton[] JGridButton = new JButton[208];
private JPanel JPanelnorthwest;
private JMenuBar JMenuBar1;
private JMenu scenarioMenu;
private JMenu editMenu;
private JMenu controlsMenu;
private JMenu helpMenu;
private JMenuItem exitItem;
private JMenuItem fontItem;
private JMenuItem foreColor;
private JMenuItem backColor;
private JMenuItem helpItem;
private JMenuItem aboutItem;
private JSlider JSlider1;
private JTextField JSliderTextfield;
/* private ImageIcon[] sandimage = new ImageIcon[1];
private ImageIcon[] whiteimage = new ImageIcon[2];
private ImageIcon[] goldenball = new ImageIcon[4];
private ImageIcon[] sandstone = new ImageIcon[3];*/
private Icon sandimage;
private Icon whiteimage;
private Icon goldenball;
private Icon sandstone;
private Icon greenfoot;
private int nPosition = 15;
/* int [][] map1 = { {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4},
{2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2},
{2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 2},
{2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 2},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2},
{2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2},
{2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2},
{3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} };*/
int [] map1 = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4,
2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2,
2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 2,
2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2,
2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
public static void main(String[] args)
{
CBallMaze frame = new CBallMaze();
frame.setIconImage(Toolkit.getDefaultToolkit().getImage("res/greenfoot.jpg"));
frame.setTitle("CBallMaze");
frame.setSize(775, 650);
frame.createGUI();
frame.setVisible(true);
JMenuBar menuBar1 = new JMenuBar();
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
System.err.println("Couldn't use the system "+"look and feel: "+e);
}
JMenu fileMenu = new JMenu("Scenario");
fileMenu.setMnemonic(KeyEvent.VK_F);
menuBar1.add(fileMenu);
JMenu fileMenu0 = new JMenu("Edit");
fileMenu0.setMnemonic(KeyEvent.VK_F);
menuBar1.add(fileMenu0);
JMenu fileMenu1 = new JMenu("Controls");
fileMenu1.setMnemonic(KeyEvent.VK_F);
menuBar1.add(fileMenu1);
JMenu fileMenu2 = new JMenu("Help");
fileMenu2.setMnemonic(KeyEvent.VK_F);
menuBar1.add(fileMenu2);
frame.setJMenuBar(menuBar1);
frame.setSize(775,650);
frame.setVisible(true);
}
private void createGUI()
{
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container window = getContentPane();
window.setLayout(new BorderLayout() );
centreWindow();
JPanelnorth = new JPanel();
JPanelnorth.setPreferredSize(new Dimension(630, 600));
JPanelnorth.setBackground(Color.white);
JPanelnorth.setLayout(new GridLayout(13,16));
window.add(JPanelnorth,BorderLayout.CENTER);
try
{
iconAct = new ImageIcon(Toolkit.getDefaultToolkit().createImage(CBallMaze.class.getResource("images/Act.jpg")));
iconRun = new ImageIcon(Toolkit.getDefaultToolkit().createImage(CBallMaze.class.getResource("images/Run.jpg")));
iconReset = new ImageIcon(Toolkit.getDefaultToolkit().createImage(CBallMaze.class.getResource("images/Reset.jpg")));
iconCompassnorth = new ImageIcon(Toolkit.getDefaultToolkit().createImage(CBallMaze.class.getResource("images/north.jpg")));
iconCompasseast = new ImageIcon(Toolkit.getDefaultToolkit().createImage(CBallMaze.class.getResource("images/east.jpg")));
iconCompasssouth = new ImageIcon(Toolkit.getDefaultToolkit().createImage(CBallMaze.class.getResource("images/south.jpg")));
iconCompasswest = new ImageIcon(Toolkit.getDefaultToolkit().createImage(CBallMaze.class.getResource("images/west.jpg")));
sandimage = new ImageIcon(Toolkit.getDefaultToolkit().createImage(CBallMaze.class.getResource("images/sand.jpg")));
whiteimage = new ImageIcon(Toolkit.getDefaultToolkit().createImage(CBallMaze.class.getResource("images/white32x32.jpg")));
goldenball = new ImageIcon(Toolkit.getDefaultToolkit().createImage(CBallMaze.class.getResource("images/sand60x60.png")));
sandstone = new ImageIcon(Toolkit.getDefaultToolkit().createImage(CBallMaze.class.getResource("images/sandstone.jpg")));
}
catch (Exception e)
{
System.err.println("Baby Icon ImageIcon "+e);
}
for( int nCount= 0; nCount < 208; nCount++ )
{
JGridButton[nCount] = new JButton("");
JPanelnorth.add(JGridButton[nCount]);
JGridButton[nCount].setBorderPainted(false);
if((nCount >= 0 && nCount<=15)
|| (nCount >= 48 && nCount <= 63)
|| (nCount >= 96 && nCount <= 111)
|| (nCount >= 144 && nCount <= 159)
|| (nCount >= 193 && nCount <= 208)
|| (nCount == 17) || (nCount == 33)
|| (nCount == 21) || (nCount == 37)
|| (nCount == 25) || (nCount == 41)
|| (nCount == 66) || (nCount == 82)
|| (nCount == 70) || (nCount == 86)
|| (nCount == 75) || (nCount == 91)
|| (nCount == 113) || (nCount == 129)
|| (nCount == 117) || (nCount == 133)
|| (nCount == 124) || (nCount == 140)
|| (nCount == 162) || (nCount == 178)
|| (nCount == 166) || (nCount == 182)
)
{
JGridButton[nCount].setIcon(sandimage);
}
else
{
JGridButton[nCount].setBackground(Color.white);
}
if(nCount == 192)
{
JGridButton[nCount].setIcon(sandstone);
}
if(nCount == 15)
{
JGridButton[nCount].setIcon(goldenball);
}
}
JPaneleast = new JPanel();
JPaneleast.setPreferredSize(new Dimension(145, 600));
JPaneleast.setBackground(Color.lightGray);
window.add(JPaneleast,BorderLayout.EAST);
JPanelSouth = new JPanel();
JPanelSouth.setPreferredSize(new Dimension(705, 50));
JPanelSouth.setBackground(Color.lightGray);
window.add(JPanelSouth,BorderLayout.SOUTH);
JPaneleasttextfields = new JPanel();
JPaneleasttextfields.setPreferredSize(new Dimension(145,100));
JPaneleasttextfields.setBackground(Color.lightGray);
JPaneleasttextfields.setLayout(new GridLayout(3,2));
JPaneleast.add(JPaneleasttextfields);
JLabelTextField1 = new JLabel("Option:");
JLabelTextField1.setPreferredSize(new Dimension(65,33));
JPaneleasttextfields.add(JLabelTextField1);
JTextField1 = new JTextField();
JTextField1.setPreferredSize(new Dimension(80 ,33));
JPaneleasttextfields.add(JTextField1);
JLabelTextField2 = new JLabel("Square:");
JLabelTextField2.setPreferredSize(new Dimension(65,33));
JPaneleasttextfields.add(JLabelTextField2);
JTextField2 = new JTextField();
JTextField2.setPreferredSize(new Dimension(80 ,33));
JPaneleasttextfields.add(JTextField2);
JLabelTextField3 = new JLabel("Direction:");
JLabelTextField3.setPreferredSize(new Dimension(65,33));
JPaneleasttextfields.add(JLabelTextField3);
JTextField3 = new JTextField();
JTextField3.setPreferredSize(new Dimension(80 ,33));
JPaneleasttextfields.add(JTextField3);
JPaneleastmiddle = new JPanel();
JPaneleastmiddle.setPreferredSize(new Dimension(160, 100));
JPaneleastmiddle.setBackground(Color.gray);
JPaneleastmiddle.setLayout(new GridLayout(3,3) );
window.add(JPaneleastmiddle,BorderLayout.NORTH);
JPaneleast.add(JPaneleastmiddle);
Jbuttonblank1 = new JButton("");
JPaneleastmiddle.add(Jbuttonblank1);
Jbuttonblank1.addActionListener(this);
Jbuttonblank1.setPreferredSize(new Dimension(80, 30));
Jbuttonblank1.setEnabled(false);
Jbuttonup = new JButton("^");
JPaneleastmiddle.add(Jbuttonup);
Jbuttonup.addActionListener(this);
Jbuttonup.setPreferredSize(new Dimension(80, 30));
Jbuttonblank2 = new JButton("");
JPaneleastmiddle.add(Jbuttonblank2);
Jbuttonblank2.addActionListener(this);
Jbuttonblank2.setPreferredSize(new Dimension(80, 30));
Jbuttonblank2.setEnabled(false);
Jbuttonleft = new JButton("<");
JPaneleastmiddle.add(Jbuttonleft);
Jbuttonleft.addActionListener(this);
Jbuttonleft.setPreferredSize(new Dimension(80, 30));
Jbuttonblank3 = new JButton("");
JPaneleastmiddle.add(Jbuttonblank3);
Jbuttonblank3.addActionListener(this);
Jbuttonblank3.setPreferredSize(new Dimension(80, 30));
Jbuttonblank3.setEnabled(false);
Jbuttonright = new JButton(">");
JPaneleastmiddle.add(Jbuttonright);
Jbuttonright.addActionListener(this);
Jbuttonright.setPreferredSize(new Dimension(80, 30));
Jbuttonblank4 = new JButton("");
JPaneleastmiddle.add(Jbuttonblank4);
Jbuttonblank4.addActionListener(this);
Jbuttonblank4.setPreferredSize(new Dimension(80, 30));
Jbuttonblank4.setEnabled(false);
Jbuttondown = new JButton("v");
JPaneleastmiddle.add(Jbuttondown);
Jbuttondown.addActionListener(this);
Jbuttondown.setPreferredSize(new Dimension(80, 30));
Jbuttonblank5 = new JButton("");
JPaneleastmiddle.add(Jbuttonblank5);
Jbuttonblank5.addActionListener(this);
Jbuttonblank5.setPreferredSize(new Dimension(80, 30));
Jbuttonblank5.setEnabled(false);
JPaneleastoptionbutton = new JPanel();
JPaneleastoptionbutton.setPreferredSize(new Dimension(160, 60));
JPaneleastoptionbutton.setBackground(Color.gray);
JPaneleastoptionbutton.setLayout(new GridLayout(2,2) );
JPaneleast.add(JPaneleastoptionbutton);
Jbuttonoption1 = new JButton("Option1");
JPaneleastoptionbutton.add(Jbuttonoption1);
Jbuttonoption1.addActionListener(this);
Jbuttonoption1.setPreferredSize(new Dimension(80, 30));
Jbuttonoption2 = new JButton("Option2");
JPaneleastoptionbutton.add(Jbuttonoption2);
Jbuttonoption2.addActionListener(this);
Jbuttonoption2.setPreferredSize(new Dimension(80, 30));
Jbuttonoption3 = new JButton("Option3");
JPaneleastoptionbutton.add(Jbuttonoption3);
Jbuttonoption3.addActionListener(this);
Jbuttonoption3.setPreferredSize(new Dimension(80, 30));
Jbuttonexit = new JButton("Exit");
JPaneleastoptionbutton.add(Jbuttonexit);
Jbuttonexit.addActionListener(this);
Jbuttonexit.setPreferredSize(new Dimension(80, 30));
JPaneleastcompass = new JPanel();
JPaneleastcompass.setPreferredSize(new Dimension(100,100));
JPaneleastcompass.setBackground(Color.lightGray);
JPaneleast.add(JPaneleastcompass);
JPanelSouthButtons = new JPanel();
JPanelSouthButtons.setPreferredSize(new Dimension(270, 30));
JPanelSouthButtons.setBackground(Color.gray);
JPanelSouthButtons.setLayout(new GridLayout(1,3) );
JPanelSouth.add(JPanelSouthButtons);
Jbuttonact = new JButton("Act");
JPanelSouthButtons.add(Jbuttonact);
Jbuttonact.setIcon(iconAct);
Jbuttonact.addActionListener(this);
Jbuttonact.setPreferredSize(new Dimension(40, 30));
Jbuttonrun = new JButton("Run");
JPanelSouthButtons.add(Jbuttonrun);
Jbuttonrun.setIcon(iconRun);
Jbuttonrun.addActionListener(this);
Jbuttonrun.setPreferredSize(new Dimension(40, 30));
Jbuttonreset = new JButton("Reset");
JPanelSouthButtons.add(Jbuttonreset);
Jbuttonreset.setIcon(iconReset);
Jbuttonreset.addActionListener(this);
Jbuttonreset.setPreferredSize(new Dimension(40, 30));
JPanelSouthSlider = new JPanel();
JPanelSouthSlider.setPreferredSize(new Dimension(200, 30));
JPanelSouthSlider.setBackground(Color.BLUE);
JPanelSouthSlider.setLayout(new GridLayout(1,3));
JPanelSouth.add(JPanelSouthSlider);
JSlider1 = new JSlider(JSlider.HORIZONTAL,200,2000,1000);
JSlider1.setPreferredSize(new Dimension(200, 30));
JPanelSouthSlider.add(JSlider1);
JButtoncompass = new JButton();
JPaneleastcompass.add(JButtoncompass);
JButtoncompass.setPreferredSize(new Dimension(100,100));
JButtoncompass.setIcon(iconCompassnorth);
}
public void centreWindow()
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
if (frameSize.height > screenSize.height)
{
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width)
{
frameSize.width = screenSize.width;
}
setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
}
public void gameEnd()
{
if(nPosition == 193)
{
}
else
{
}
}
public void Option1()
{
JTextField1.setText("Option1");
}
public void Option2()
{
JTextField1.setText("Option2");
}
public void Option3()
{
JTextField1.setText("Option3");
}
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
gameEnd();
if(source == Jbuttonoption1)
{
Option1();
}
if(source == Jbuttonoption2)
{
Option2();
}
if(source == Jbuttonoption3)
{
Option3();
}
if(source == Jbuttonup)
{
JButtoncompass.setIcon(iconCompassnorth);
JTextField3.setText("N");
JGridButton[nPosition -16].setIcon(goldenball);
JGridButton[nPosition].setIcon(sandimage);
//JTextField2.set
nPosition = nPosition -16;
}
if(source == Jbuttonright)
{
JButtoncompass.setIcon(iconCompasseast);
JTextField3.setText("E");
JGridButton[nPosition +1].setIcon(goldenball);
JGridButton[nPosition].setIcon(sandimage);
nPosition = nPosition +1;
}
if(source == Jbuttondown)
{
JButtoncompass.setIcon(iconCompasssouth);
JTextField3.setText("S");
JGridButton[nPosition +16].setIcon(goldenball);
JGridButton[nPosition].setIcon(sandimage);
nPosition = nPosition +16;
}
if(source == Jbuttonleft)
{
if(nPosition <= 0)
{
}
else{
JButtoncompass.setIcon(iconCompasswest);
JTextField3.setText("W");
JGridButton[nPosition -1].setIcon(goldenball);
JGridButton[nPosition].setIcon(sandimage);
nPosition = nPosition -1;}
}
if(source == Jbuttonoption1)
{
}
if(source == Jbuttonoption2)
{
}
if(source == Jbuttonoption3)
{
}
if(source == Jbuttonexit)
{
System.exit(EXIT_ON_CLOSE);
}
}
}
for( int nCount= 0; nCount < 208; nCount++ )
{
JGridButton[nCount] = new JButton("");
JPanelnorth.add(JGridButton[nCount]);
JGridButton[nCount].setBorderPainted(false);
if((nCount >= 0 && nCount<=15)
|| (nCount >= 48 && nCount <= 63)
|| (nCount >= 96 && nCount <= 111)
|| (nCount >= 144 && nCount <= 159)
|| (nCount >= 193 && nCount <= 208)
|| (nCount == 17) || (nCount == 33)
|| (nCount == 21) || (nCount == 37)
|| (nCount == 25) || (nCount == 41)
|| (nCount == 66) || (nCount == 82)
|| (nCount == 70) || (nCount == 86)
|| (nCount == 75) || (nCount == 91)
|| (nCount == 113) || (nCount == 129)
|| (nCount == 117) || (nCount == 133)
|| (nCount == 124) || (nCount == 140)
|| (nCount == 162) || (nCount == 178)
|| (nCount == 166) || (nCount == 182)
)
{
JGridButton[nCount].setIcon(sandimage);
}
else
{
JGridButton[nCount].setBackground(Color.white);
}
if(nCount == 192)
{
JGridButton[nCount].setIcon(sandstone);
}
if(nCount == 15)
{
JGridButton[nCount].setIcon(goldenball);
}
}
我想我必须删除这段代码,并将其替换为数组的其他代码。
if((nCount >= 0 && nCount<=15)
|| (nCount >= 48 && nCount <= 63)
|| (nCount >= 96 && nCount <= 111)
|| (nCount >= 144 && nCount <= 159)
|| (nCount >= 193 && nCount <= 208)
|| (nCount == 17) || (nCount == 33)
|| (nCount == 21) || (nCount == 37)
|| (nCount == 25) || (nCount == 41)
|| (nCount == 66) || (nCount == 82)
|| (nCount == 70) || (nCount == 86)
|| (nCount == 75) || (nCount == 91)
|| (nCount == 113) || (nCount == 129)
|| (nCount == 117) || (nCount == 133)
|| (nCount == 124) || (nCount == 140)
|| (nCount == 162) || (nCount == 178)
|| (nCount == 166) || (nCount == 182)
)
最佳答案
看起来您想创建一个由按钮保存的图像网格。如果是这样,那么只需创建 JButton 的二维数组,不要给出按钮名称,并在 for 循环中创建 JButton,同时将它们添加到数组和使用 JPanel 的 GridLayout 中。然后,您可以使用相同的网格为每个按钮分配图像图标。
您的 map 应由文本文件保存,而不是在代码中硬编码,然后您可以将 map 读入其自己的二维数组中,并将其用作创建和迭代按钮网格的基础。
例如,
// first read in the text file and fill the map 2D int array
for (int row = 0; row < btnGrid.length; row++) {
for (int col = 0; col < btnGrid[row].length; col++) {
int value = map[row][col]; // holds value for icons array
Icon icon = icons[value]; // an array of ImageIcons
btnGrid[row][col] = new JButton(icon);
btnGrid[row][col].addActionListener(someListener);
btnPanel.add(btnGrid[row][col]);
}
}
在 JButton 的 Action 或 ActionListener(此处标记为 someListener
)中,您可以根据需要在按下按钮时更改按钮的状态(可能是其图标)。
关于java - 将按钮添加到数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29259624/
我正在尝试创建一个包含 int[][] 项的数组 即 int version0Indexes[][4] = { {1,2,3,4}, {5,6,7,8} }; int version1Indexes[
我有一个整数数组: private int array[]; 如果我还有一个名为 add 的方法,那么以下有什么区别: public void add(int value) { array[va
当您尝试在 JavaScript 中将一个数组添加到另一个数组时,它会将其转换为一个字符串。通常,当以另一种语言执行此操作时,列表会合并。 JavaScript [1, 2] + [3, 4] = "
根据我正在阅读的教程,如果您想创建一个包含 5 列和 3 行的表格来表示这样的数据... 45 4 34 99 56 3 23 99 43 2 1 1 0 43 67 ...它说你可以使用下
我通常使用 python 编写脚本/程序,但最近开始使用 JavaScript 进行编程,并且在使用数组时遇到了一些问题。 在 python 中,当我创建一个数组并使用 for x in y 时,我得
我有一个这样的数组: temp = [ 'data1', ['data1_a','data1_b'], ['data2_a','data2_b','data2_c'] ]; // 我想使用 toStr
rent_property (table name) id fullName propertyName 1 A House Name1 2 B
这个问题在这里已经有了答案: 关闭13年前。 Possible Duplicate: In C arrays why is this true? a[5] == 5[a] array[index] 和
使用 Excel 2013。经过多年的寻找和适应,我的第一篇文章。 我正在尝试将当前 App 用户(即“John Smith”)与他的电子邮件地址“jsmith@work.com”进行匹配。 使用两个
当仅在一个边距上操作时,apply 似乎不会重新组装 3D 数组。考虑: arr 1),但对我来说仍然很奇怪,如果一个函数返回一个具有尺寸的对象,那么它们基本上会被忽略。 最佳答案 这是一个不太理
我有一个包含 GPS 坐标的 MySQL 数据库。这是我检索坐标的部分 PHP 代码; $sql = "SELECT lat, lon FROM gps_data"; $stmt=$db->query
我需要找到一种方法来执行这个操作,我有一个形状数组 [批量大小, 150, 1] 代表 batch_size 整数序列,每个序列有 150 个元素长,但在每个序列中都有很多添加的零,以使所有序列具有相
我必须通过 url 中的 json 获取文本。 层次结构如下: 对象>数组>对象>数组>对象。 我想用这段代码获取文本。但是我收到错误 :org.json.JSONException: No valu
enter code here- (void)viewDidLoad { NSMutableArray *imageViewArray= [[NSMutableArray alloc] init];
知道如何对二维字符串数组执行修剪操作,例如使用 Java 流 API 进行 3x3 并将其收集回相同维度的 3x3 数组? 重点是避免使用显式的 for 循环。 当前的解决方案只是简单地执行一个 fo
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我有来自 ASP.NET Web 服务的以下 XML 输出: 1710 1711 1712 1713
如果我有一个对象todo作为您状态的一部分,并且该对象包含数组列表,则列表内部有对象,在这些对象内部还有另一个数组listItems。如何更新数组 listItems 中 id 为“poi098”的对
我想将最大长度为 8 的 bool 数组打包成一个字节,通过网络发送它,然后将其解压回 bool 数组。已经在这里尝试了一些解决方案,但没有用。我正在使用单声道。 我制作了 BitArray,然后尝试
我们的数据库中有这个字段指示一周中的每一天的真/假标志,如下所示:'1111110' 我需要将此值转换为 boolean 数组。 为此,我编写了以下代码: char[] freqs = weekday
我是一名优秀的程序员,十分优秀!