小编ala*_*ter的帖子

MongoDb查询条件比较2个字段

我有一个集合T,有2个字段:Grade1而且Grade2,我想选择那些有条件的Grade1 > Grade2,我怎样才能得到像MySQL一样的查询?

Select * from T Where Grade1 > Grade2
Run Code Online (Sandbox Code Playgroud)

compare mongodb

93
推荐指数
4
解决办法
8万
查看次数

你如何导入字体?

我想知道如何导入字体.

我正在尝试使用自定义下载的字体,但由于大多数计算机将运行此字体,因此它不是默认字体.即使他们没有字体,我怎样才能使字体工作?

我正在将它用于游戏画面,需要用它显示乐谱,并希望乐谱文本是相同的字体.这是图像,

在此输入图像描述

如果重要,我的电脑上的字体名称是 Terminal

编辑:我假设它必须在java文件的目录中有字体,并有一些方法使用它,但我不知道如何.或者,还有更好的方法?

编辑2:我找到了一个很好的教程,如何做到这一点,但需要一些帮助我如何使用这个... 点击我的链接

EDIT3:

URL fontUrl = new URL("http://www.webpagepublicity.com/" + "free-fonts/a/Airacobra%20Condensed.ttf");
Font font = Font.createFont(Font.TRUETYPE_FONT, fontUrl.openStream());
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
g.setFont(font);
Run Code Online (Sandbox Code Playgroud)

错误信息

File: F:\Computer Science\draw.java  [line: 252]
Error: F:\Computer Science\draw.java:252: font is not public in java.awt.Component; cannot be accessed from outside package
Run Code Online (Sandbox Code Playgroud)

这是我正在尝试的:

URL fontUrl = new URL("http://img.dafont.com/dl/?f=badaboom_bb");
Font font = Font.createFont(Font.TRUETYPE_FONT, fontUrl.openStream());
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
g.setFont(font);
Run Code Online (Sandbox Code Playgroud)

Edit4:

File fontfile = new File("TexasLED.ttf");
File.toURI(fontfile).toURL(fontfile);
URL fontUrl = new URL("fontfile");
Run Code Online (Sandbox Code Playgroud)

错误 …

java fonts awt

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

为什么JScrollPane中的JPanel不能滚动?

我有一个JPanel(黄色)放入JScrollPane.

PIC1

当我输入一些文本时JTextPane,它会调整大小,但垂直滚动条仍然不活动.yelowPanel.getSize()返回与之前相同的值.(您可以在redPanel上看到它).

PIC2

那我怎么刷新yellowPanel?我想垂直滚动面板.我试过了:

panelCreating.revalidate();
panelCreating.invalidate();
panelCreating.repaint();
Run Code Online (Sandbox Code Playgroud)

仅适用,panelCreating.setPreferredSize(new Dimension(333, 777));但我不知道要设置的大小.这取决于内容.

有一个小例子:

package swingtest;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

public class SwingTest extends JFrame {

    public SwingTest() {
        initComponents();
    }

    public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new SwingTest().setVisible(true);
            }
        });
    } …
Run Code Online (Sandbox Code Playgroud)

java swing jscrollpane

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

服务器不接受nio中的一个客户端

我正在尝试构建一个聊天应用程序.我有一个代码将数据从客户端发送到服务器.当一个或多个客户端登录时(当客户端程序运行一次或多次时).server将不接受除首次连接之外的其余连接.请帮我解决这个问题,这是我的代码:

public class Server
{

//Creating non blocking socket

public void non_Socket() throws Exception {

    ServerSocketChannel ssChannel = ServerSocketChannel.open();
    int port = 80;
    int i=0;
    ssChannel.socket().bind(new InetSocketAddress(port));
    ssChannel.configureBlocking(false);
    while(true)
    {
        SocketChannel sc = ssChannel.accept();`

        if (sc == null) 
        {
            System.out.println("Socket channel is null");
            Thread.sleep(5000);
        }
        else 
        {
            System.out.println("Socket channel is not null");
            System.out.println("Received an incoming connection from " +
                    sc.socket().getRemoteSocketAddress()); 
            new PrintRequest(sc,i).start(); 
            i++;
        }
    }
}

public static void main(String [] abc) throws Exception
{
    new Server().non_Socket();
}
}

class …
Run Code Online (Sandbox Code Playgroud)

java networking nio

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

为什么静态方法无法在Java中隐藏实例方法

class TestOverriding {

    public static void main(String aga[]) {
        Test t = new Fest();
        t.tests();
    }
}

class Test {
    void tests() {
        System.out.println("Test class : tests");
    }
}
class Fest extends Test {   
    static void tests() {
        System.out.println("Fest class : tests");
    } 
}
Run Code Online (Sandbox Code Playgroud)

测试类是超类,而Fest是它的子类,因为即使我们知道静态方法也不能被覆盖,否则我会收到类似“静态方法无法在Java中隐藏实例方法”的错误,有人可以对此进行解释,在此先感谢。

java

5
推荐指数
2
解决办法
4718
查看次数

Java-Scanner 不适用于 nextByte()

Scanner Sc = new Scanner(new File("Input.bin"));
String s = Sc.nextLine();
fsize = Integer.parseInt(s); // Reads 4

s = Sc.nextLine();
int mapSize = Integer.parseInt(s);     // Reads 3 
for (int i = 0; i < mapSize; i++)
{
    byte value = 0;
    value = Sc.nextByte();  // Here it is throwing the exception it should have
                            // print the ascii of 'b' which is 98????

    String key = Sc.nextLine();
    key = key.trim();

    dcMap.put(key, (char)value);
 // System.out.println(key + " " + (char)value);
}
Run Code Online (Sandbox Code Playgroud)

Input.bin …

java

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

Spring security 重定向到状态码为 999 的页面

成功登录后,spring 重定向到/error具有以下内容的页面

{
  "timestamp" : 1586002411175,
  "status" : 999,
  "error" : "None",
  "message" : "No message available"
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 spring-boot 2.2.4

我的配置:

spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
spring.mvc.servlet.load-on-startup=1
spring.mvc.throw-exception-if-no-handler-found=true
spring.resources.add-mappings=false
Run Code Online (Sandbox Code Playgroud)
@Configuration
public class DispatcherContextConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
    }
}
Run Code Online (Sandbox Code Playgroud)
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class AppSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(WebSecurity web) {
        web.ignoring().antMatchers("/favicon.ico", "/resources/**");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
                .authorizeRequests()
                .antMatchers("/api/**").permitAll()
                .antMatchers("/registration/**").anonymous()
                .anyRequest().authenticated()
                .and()
                    .headers() …
Run Code Online (Sandbox Code Playgroud)

java spring-security

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

将类变量引用到局部变量

为什么有些人在方法中对字段变量进行新的引用?

public class Foo {
    int mFoo[] = {1, 2, 3};

    void method() {
        int foo[] = mFoo; // WHY not just use mFoo?

        print(foo[0]); // WHY not just use mFoo?
    }
}
Run Code Online (Sandbox Code Playgroud)

java

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

MongoCursor没有count()方法?

所以我的代码是:

FindIterable<Document> findIterable = collection.find().skip(20).limit(10);
MongoCursor<Document> cursor = findIterable.iterator();
while (cursor.hasNext()) {
    Document doc = cursor.next();
    // My stuff with documents here
}
cursor.close(); // in finally block
Run Code Online (Sandbox Code Playgroud)

现在我想知道total count之前skip和之前的文件limit.

对于完全相同的问题有一个答案,但我mongo-java-driver v3.1.0和我使用的API是不同的.有没有方法count()size()在这两个FindIterableMongoCursor类.谢谢!

UPDATE

似乎唯一的解决方法是再次打电话给mongodb:collection.count正如@Philipp所说

java mongodb mongodb-java mongo-java-driver

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