我正在阅读一些文字C language.文字说switch{} case只能接受整数类型.
我只是好奇为什么switch{} case不接受其他类型,如浮点数或字符串.这背后有什么理由吗?
非常感谢.
我是c ++的新手,我正在尝试计算Point(x,y,z)集的凸包C++.
我在main方法中调用了以下方法:
vector<Point> convexHull(Point Points[], int n) {
vector<Point> v;
// Find the bottommost Point
int ymin = Points[0].getY();
int min = 0;
for (int i = 1; i < n; i++) {
int y = Points[i].getY();
// Pick the bottom-most or chose the left most Point in case of tie
if ((y < ymin) || (ymin == y && Points[i].getX() < Points[min].getX()))
ymin = Points[i].getY(), min = i;
}
// Place the bottom-most Point at first …Run Code Online (Sandbox Code Playgroud) 我正在用Java编写模拟,但是没有很多使用Graphics对象的经验.我写了一堂课
public class RoadNetwork extends JPanel {
BufferedImage truck1;
public RoadNetwork() throws IOException{
truck1 = ImageIO.read(getClass().getResource("Truck.png"));
}
protected void paintcomponent (Graphics g) {
super.paintComponent(g);
g.drawImage(car1, 0, 0, 100, 100, this);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的main函数中,我按如下方式初始化类:
JFrame F1 = new JFrame();
F1.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
F1.setSize(1280,760);
RoadNetwork roadnetwork = new RoadNetwork();
roadnetwork.setPreferredSize(new Dimension(500,500));
roadnetwork.setVisible(true);
constraints.gridx = 40;
constraints.gridy = 40;
F1.add(roadnetwork, constraints);
F1.setVisible(true);
Run Code Online (Sandbox Code Playgroud)
但是,我只得到一个灰色的框架作为输出,没有图像.我已经通过将图像作为单独的ImageIcon添加到框架中来测试图像,这是有效的.但是,我似乎无法在框架中显示RoadNetwork类.我应该以某种方式调用paintcomponent函数吗?我究竟做错了什么?